Opening VS2k5 .Net 2.0 projects in VS2k8

I'm starting a new gig right now and one of the sweet things about it is that I'm going to be working in .NET 3.5 straight off the bat.  Hopefully I'll have some more time to blog about things to do with the framework and the language over the next number of weeks.

Because of the normal process that most companies seem to have for assimilating new people to a team, I spent a couple of days with no direct network access.  Instead of just reading the documentation, I wanted to get some code written so that I could start handing it off to the other team members and training them up on the code architecture that I envision.  My only option for writing code was my Visual Studio 2005 .NET 2.0 laptop which handily did the trick.  Once I got my network access I quickly moved my source files over to the other machine (actually a VPC) and fired up Visual Studio 2008 to make sure everything was still kosher.

When it compiled on the first try I immediately set out to change some of my initial code to use the basic language features that are new in VS2k8.  I went through the DTOs that I'd built and changed all to use the simple property syntax.  Again everything compiled just fine.  I was on a roll.

For some reason I ended up in the project properties window today and I noticed that the project (one that I'd moved up from VS2k8) was still using .NET 2.0.  It's a simple combobox selection to change to .NET 3.0, but it isn't done automatically when the solution conversion routine is run.  All projects need to be changed manually.  You don't notice that this has happened because VS2k8 has some sweet compiler sugar that allows you to use the new language features in .NET 2.0, 3.0 or 3.5. 

When I give my talk on the new language features that are available in VS2k8, I usually give some warning about things like a lack of readability because of the 'var' type or that extension methods are probably going to be over used or used in a dangerous way.  I never thought that I'd get pinched by that feature that I have lauded over and over.  Apparently poor OO and coding practices aren't the only thing that will be causing people problems when they move their VS2k5 projects up to VS2k8.

Posted By: Donald Belcham

Published at

Comments

Jay R. Wren
12/13/2007 05:12 PM by
Jay R. Wren

The issue isn't that VS2k8 has "sweet compiler sugar that allows you to use the new language features in .NET 2.0, 3.0 or 3.5".

VS2k8 is ALWAYS using the C# 3.0 compiler. PERIOD. done. C# 3.0 code ALWAYS compiles down to IL which will run on the 2.0 runtime (there is no newer runtime).

So the "2.0, 3.0, 3.5" combo box is really just a filter for what assemblies you reference. Have you referenced WPF? Then studio (msbuild) will warn you that this is not a 2.0 target, and to use 3.0. Trying to use LINQ or something else from System.Core? You will get a warning to use 3.5.

What is a bummer is that all the nice languages features such as auto properties and use of 'var' will not ever work in VS2k5. So even though the project format is portable, its a bit useless.

Donald Belcham
12/13/2007 06:39 PM by
Donald Belcham

The "sweet compiler sugar" that I was eluding to was exactly what you explained. Regardless of the target version of the framework, the compiler works it's own magic and ensures that the IL will work against that framework version.

The issue that I actually ran into wasn't that though. I wanted to see my VS2k5 (.NET 2.0) solution get upgraded (as the wizard said it was doing) and the projects in that solution either automagically get promoted to .NET 3.5 or have it ask me if I wanted the upgrade wizard to do this for me.

The post is just a warning that you're not going to be upgraded to .Net 3.5 if you run the upgrade wizard. You will need to change that setting manually.