I had a VS2005 solution and wanted to get off VS2005 for the new year. I was mostly happy with the upgrade process and pleasantly surprised to see that my build scripts mostly still worked.
My question is around the multi-targeting feature – I don’t have .NET 3.5 installed on my servers, so I have to continue to target .NET 2.0. That worked, mostly, but I found that I could do things like
var returnMe = "result: " + result.ToString();
…and still debug the project successfully.
When I got that code up to the build server, the build failed, saying that “var” wasn’t defined.
So, which should I be expecting?
- VS2008, targeting .NET 2.0, should throw errors when I try to do C# 3 things
- the build server, being aware that I’m targeting .NET 2.0, should understand what I’m doing and compile the thing into a 2.0-compatible binary
Any ideas?
The problem appears to be that the build server does not have the right compiler. You can build it on your workstation, right?
Many of the .NET 3.0 “features” are just syntax bits that revert to CLR 2 code at compile time.
varis one of them — when it compiles, the compiler converts var to the appropriate type.There is a pretty informative post on this at http://weblogs.asp.net/shahar/archive/2008/01/23/use-c-3-features-from-c-2-and-net-2-0-code.aspx