可以应用构建在.NET 4.5 .NET 4.0上运行? [英] Can application built with .NET 4.5 run on .NET 4.0?

查看:446
本文介绍了可以应用构建在.NET 4.5 .NET 4.0上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目的目标是到.NET 4.5。它不使用任何新的4.5的方法,所以它实际上是正常工作的机器上只安装了.NET 4.0。

这是所有好,直到我加入了一些扩展方法和思考。然后,当我跑这个.NET 4.5程序4.0的机器上,它失败,System.TypeLoadException:无法加载类型System.Runtime.CompilerServices.ExtensionAttribute从装配mscorlib程序。已归档以及<一个著名的ExtensionAttribute程序href="http://www.mattwrock.com/post/2012/02/29/What-you-should-know-about-running-ILMerge-on-Net-45-Beta-assemblies-targeting-Net-40.aspx">here.

另一种快速的方法来测试,这是添加以下行。然后在只有.NET 4.0上运行时程序会抛出异常。

<$p$p><$c$c>Console.WriteLine(typeof(System.Runtime.CompilerServices.ExtensionAttribute).Assembly.FullName);

我不知道是否有一种方法来解决它。例如,ILMerge(用作记录在链接正确/ targetplatform选项时)实际改变了ExtensionAttribute从mscorlib程序到System.Core程序,如果该项目为目标,以.NET 4.0(含4.5安装)。但它似乎没有工作,有针对性地.NET 4.5的项目。

我知道这是一个长镜头。但只是想看看是否有人有其他的想法,因为它是如此接近。

感谢。

解决方案

在一般情况下,这是不行的。它确实工作的在某些情况下的,因为4.5是到位替代4.0,但它不会在一般的工作。我个人而言,可见问题已移动到不同的组件类型,并绑定与没有设置正确,就像你所看到的。反射类型不被移动在4.5的唯一类型。

  

我的项目的目标是到.NET 4.5。它不使用任何新的4.5的方法,所以它实际上是正常工作的机器上只安装了.NET 4.0。

如果是这样的话,你可以只改变您的应用程序面向.NET 4.0。这应该允许它安全的机器上只安装了.NET 4中运行。

My project is targeting to .NET 4.5. It doesn't use any new 4.5 methods, so it actually works fine on the machine with only .NET 4.0 installed.

This is all good until I added some extension methods and reflection. Then when I ran this .NET 4.5 program on the 4.0 machine, it failed with "System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly mscorlib". The famous ExtensionAttribute program that has been documented well here.

Another quick way to test this is to add the following line. Then the program will throw the exception when running on .NET 4.0 only.

Console.WriteLine(typeof(System.Runtime.CompilerServices.ExtensionAttribute).Assembly.FullName);

I'm wondering if there is a way to work around it. For example, the ILMerge (when using the correct /targetplatform option as documented in the link) actually changes the ExtensionAttribute from mscorlib to System.Core if the project is target to .NET 4.0 (with 4.5 installed). But it doesn't seem to work on the project targeted to .NET 4.5.

I know this is a long shot. But just want to see if anyone has other ideas since it was so close.

Thanks.

解决方案

In general, this will not work. It does work in some cases since 4.5 is an in place replacement for 4.0, but it's not going to work in general. I've, personally, seen problems with types that have moved into different assemblies, and the bindings aren't setup correctly, just like you're seeing. The reflection types aren't the only types that were moved in 4.5.

My project is targeting to .NET 4.5. It doesn't use any new 4.5 methods, so it actually works fine on the machine with only .NET 4.0 installed.

If this is the case, you could just change your application to target .NET 4.0. This should allow it to run safely on a machine with only .NET 4 installed.

这篇关于可以应用构建在.NET 4.5 .NET 4.0上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆