views:

36

answers:

1

I have a number of assemblies which were built with VS2005 (.Net 2.0). I would like to reference them in a VS2010 project. Do they need to be rebuilt in VS2010 to execute in the .Net 4.0 framework or will they continue to execute in the .Net 2.0 Framework?

+1  A: 

Your .NET 2.0 assemblies will continue to work fine when referenced from a .NET 4.0 project in Visual Studio 2010.

This assumes that you have both .NET 2.0 and .NET 4.0 frameworks installed on the machines where your application will run. (.NET 4.0 framework is brand new from the "ground up" whereas the like of .NET 3.0 and 3.5 were "additive").

By default, your pre-built assemblies will continue to reference the .NET 2.0 framework (i.e mscorlib.dll etc.) whilst your new Visual Studio 2010 will reference the .NET 4.0 framework versions. See the screen-grab from reflector below:

alt text

(VS2005Test is a class library built against .NET 2.0 in VS2005, and TestReferencingVS2005.exe is a console application built against .NET 4.0 in Visual Studio 2010)

Visual Studio 2010 also supports "multi-targeting" with projects at the source code level. This means that you can load the source for a project that was written in VS 2005 and targets the .NET 2.0 framework, and VS2010 will allow that project to continue to target the 2.0 framework. Of course, you can also upgrade it to use 4.0.

So, if you don't mind re-building, and it's not going to cause you problems, you can use Visual Studio 2010 have both your assemblies and final application all targeting .NET 2.0 or "upgrade" the assemblies to .NET 4.0 along with your application.

CraigTP
The Reflector view is not representative for what happens at runtime.
Hans Passant
@Hans - Really? What happens at runtime, then?
CraigTP
It uses the V4.0 version of mscorlib.dll
Hans Passant