Can .NET 2.0 assemblies run under .NET 4.0?

微笑、不失礼 提交于 2019-12-10 14:21:47

问题


I have developed a .NET solution that consists of several assemblies, most of which are small helper assemblies that target version 2.0 of the .NET Framework. The remaining assemblies are MVC 3 Web applications, which must necessarily target version 4.0 of the .NET Framework. My solution has no other external dependencies besides the .NET and MVC Frameworks.

My question is the following: When I deploy this solution to customers, do I have to deploy both versions of the .NET Framework, or can I just deploy version 4.0? Can .NET 2.0 assemblies run under .NET 4.0?


回答1:


You only need the latest version. It's downward compatible.




回答2:


Yes, the dependencies embedded in the assembly on .NET 2.0 assemblies are automatically translated to their 4.0 version. But it runs with a version of those assemblies it has never been tested on. They are highly compatible but contain several bug fixes, bugs that you might unknowingly have a dependency on. Nobody can give you a 100% guarantee.

Just try it.




回答3:


The answer is yes, assemblies developed for .NET 2.0 will run correctly under .NET 4.0




回答4:


Yes and no (at least for .Net 4.5). While it is backwards compatible, the default is to run the code on the associated .Net version as noted here:

The .NET Framework 4.5 and its point releases are backward-compatible with apps that were built with earlier versions of the .NET Framework. In other words, apps and components built with previous versions will work without modification on the .NET Framework 4.5. However, by default, apps run on the version of the common language runtime for which they were developed, so you may have to provide a configuration file to enable your app to run on the .NET Framework 4.5. For more information, see the Version compatibility for apps section earlier in this article.

After adding a MyLovely.exe.config file everything worked fine:

<configuration>
  <startup>
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>


来源:https://stackoverflow.com/questions/7084028/can-net-2-0-assemblies-run-under-net-4-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!