views:

2650

answers:

8

Are there any advantages compiling for .NET Framework 3.5 instead of 2.0?

For example less memory consumption, faster startup, better performance...

Personally I don't think so however, I may have missed something.

Edit: Of course there are more features in the 3.5 framework, but these are not the focus of this question.

Edit2: There seem to be no advantages.

Edit3: Yes I meant targeting the Framework. I have installed the latest 3.5 SP1 and VS 2008 so what's the difference between compiling with and targeting a framework? I can target the framework in the project options but how do I 'compile with' a specific framework version? I did not know that there is a difference.

Edit4: So for now we agree that there are no advantages.

Thanks for you opinions

A: 

3.5 has classes that 2.0 doesn't. Func<...> for instance. If you aim for 2.0, you can't use them.

Patrick
+1  A: 

I haven't found any. An obvious disadvantage, if you don't need the 3.5 specific features, is that the 3.5 code base is younger and is therefore possible, albeit unlikely, that there is some bug lurking around.

Sklivvz
+5  A: 

There's a difference between compiling and targeting.

Compiling the code with the (for example) C# 3.0 compiler will probably give you a boost on performance (very little one anyway) as some optimization for the generated IL code migh have been included. It also allows you to use some of the new features like automatic properties or lambda expressions.

Targeting for a given framework will ensure your assembly works for that framework (and posteriors) and will fail if you target for 2.0 and are using a 3.5 library. No performance improvements will be directly related to that unless your substituting a class from one framework with another "fastest" class. For example, targeting .NET 1.1 won't allow you to use generics and therefore you'll have to use the ArrayList which is considerably slower than List (due to boxing and unboxing).

Jorge Córdoba
+1  A: 

There are two things to remember in regards to .NET 2.0 and .NET 3.5.

  1. The .NET Framework 3.5 is just a few libraries that run on top of .NET 2.0.
  2. When developing in Visual Studio 2008 and targeting .NET 2.0 you can still use certain C# 3.0 language features such as Extension Methods since they are in fact a feature of the C# 3.0 (or .NET 3.5) compiler. See this link: http://www.codethinked.com/post/2008/02/Using-Extension-Methods-in-net-20.aspx
Chris Pietschmann
+1  A: 

There is no benefit to compiling to the 3.5 framework if you are not using any classes from that version of the framework.

Aaron Fischer
+1  A: 

I presume that you must mean targeting the .NET 3.5 framework for your compilation? If so then as others have said I don't believe you will see much difference.

However, if you're talking about using the updated compilers then there are various changes and break changes described for both C# and VB at the following links:

Richard C. McGuire
+1  A: 

I believe that a different compiler ships with each version of Visual Studio. For example in the case of C# the 2.0 compiler shipped with Visual Studio 2005 and the C# 3.0 shipped with Visual Studio 2008. Depending upon which version of Visual Studio you use you end up with a different compiler.

Targeting a framework refers to specifically which version of the framework you wish to target during the compilation process; targeting frameworks is a new feature of Visual Studio 2008. For instance I could have a solution open in Visual Studio 2008 and target v2.0 of .Net. The result would be that I wouldn't have any of the 3.0 or 3.5 .Net features available to me during that compilation, for example WPF.

Richard C. McGuire
+1  A: 

If your .NET assembly targets .NET 3.5, the resulting application will look for and require the .NET 3.5 libraries, and that's that. These libraries come with numerous additional classed not found in the .NET 2.0 framework, so that would be the advantage to targetting those libraries.

If you however compile C# code with the C# 3.0 compiler shipping with e.g. Visual Studio 2008 and suited for .NET 3.5, but have your assembly target .NET 2.0, you will still only need the regular .NET 2.0 libraries, and despite this actually use certain .NET 3.5 compiler features, as a number of those features are only making use of .NET 2.0 code in the end. Read more about this here: http://weblogs.asp.net/shahar/archive/2008/01/23/use-c-3-features-from-c-2-and-net-2-0-code.aspx

Jonas