views:

859

answers:

6

Our codebase where I work is .NET 2.0. For our new assembly/DLLs/web applications I would love to take advantage of what 3.5 has to offer.

Can one mix .NET frameworks(per assembly) in a solution? Are there any IIS related caveats to this?

I would love to hear any positive/negative/howto feedback. Let me know!

Thanks!

+2  A: 

EDIT: I was wrong you can. You can go reference 3.+ assemblies in 2.0, because the CLR is the same. This will not be the case when going from 2.0/3.+ to 4.0 as there is a new version of the CLR.

http://abdullin.com/how-to-use-net-35-syntax-and-compiler-features-for-net-20/

Kevin
As far as I can see, this is perfectly possible the other way around, but you'll get warnings when adding a reference to a 3.5 project in a 2.0 project. Also, the referenced 3.5 code might result in errors but I'm not sure about that.
Webleeuw
This isn't strictly true. 2.0, 3.0 and 3.5 all run on the same 2.0 CLR. (ignoring service packs etc). It's perfectly possible to use 3.5 assemblies from 2.0 code provided you aren't dependant on any of the service pack changes. You can do it directly in visual studio, it just gives you a warning. I doubt it's officially supported but it works, It's even possible to do stuff like Linq from 2.0 provided you manually locate and reference the required assemblies.
Simon P Stevens
Yeah, that was silly of me. I was thinking about going from 1.0 to 2.0.
Kevin
+6  A: 

Hello Micah,

Yes you can do this in Visual Studio and it is called Multi-Targeting.

Scott Guthrie has a great blog-entry on Multi-Targeting Support in Visual Studio.

VS 2008 was the first release of Visual Studio that included multi-targeting support for .NET. What this meant was that you could use VS 2008 to create and edit not only .NET 3.5 projects, but also .NET 3.0 and .NET 2.0 projects as well. This allowed developers to more quickly upgrade and take advantage of new Visual Studio tooling features – without having to necessarily require the newer version of .NET to be installed on the clients and production servers running their applications.

Cheers

Shaharyar
And you can certainly have a 2.0 Assembly alongside a 3.5 assembly/project in a single solution, if you want to leave old projects untouched. As far as IIS is concerned, you'll just need to have the 3.5 framework (there is also a 3.5 Service Pack 1) installed on the server. The 2.0, 3.0, and 3.5 frameworks can be installed simultaneously without any issues.
This is why I love stackoverflow. Thanks for the link and the explanation!
Micah
Nice, answer, but this is not the question that the poster asked - they asked about using multiple versions of the .Net framework in the **same assembly**
Kragen
A: 

If you can wait for the new .NET 4.0 framework, you will be able to run dll's for each version side by side in the same process.

hambonious
Simon P Stevens
+1  A: 

This should not be an issue. .NET 2.0 RTM through .NET 3.5 SP2 all use the exact same version of the CLR. They only differ by the number of assemblies that are included. The assembly format is the same. Of course, if you do take advantage of an assembly that's only included with .NET 3.5, you must make sure that 3.5 is actually installed on the target machine. You'll find out quickly if it isn't.

3.5 should already be on the machine if it has Windows Update enabled. If not, it takes a dozen or so minutes to get it on there.

Hans Passant
A: 

As a side note, we have some old 1.0 libraries that we used in 2.0 and still use in 3.5, without recompiling. So there's some backwards compatibility there.

quillbreaker
+1  A: 

You cannot have .Net 1.1 assmeblies running in the same process as a .Net 2.0+ assembly - attempting to do so will produce a failure.

With regards to IIS, this means that you cannot have .Net 1.1 sites / virtual directories running in the same application pool as .Net 2.0 and above sites - you need to create a separate app pool to keep the .Net 1.1 code running in a different process. (This can only be done in IIS 6.0 and above, i.e. not in Windows XP)

However as nobugz says - .Net 2.0 through to .Net 3.5 all use the same CLR, and so different versions of .Net code can be mixed in the same assembly without worry - this also holds true for IIS (.Net 2.0 and .Net 3.5 code can happily co-exist in the same app pool)

Kragen