Reputation: 19742
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?
Upvotes: 5
Views: 1952
Reputation: 2341
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>
Upvotes: 0
Reputation: 941347
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.
Upvotes: 7
Reputation: 5340
The answer is yes, assemblies developed for .NET 2.0 will run correctly under .NET 4.0
Upvotes: 1