针对.NET 2.0的VS2008并没有阻止我使用C#3功能

dno*_*ord 4 .net multitargeting visual-studio-2008 visual-studio .net-2.0

我有一个VS2005解决方案,想要在新的一年里下VS2005.我对升级过程感到非常满意,并且惊喜地看到我的构建脚本大部分仍然有效.

我的问题是围绕多目标功能 - 我没有在我的服务器上安装.NET 3.5,所以我必须继续以.NET 2.0为目标.这主要是有效的,但我发现我可以做的事情

var returnMe = "result: " + result.ToString();
Run Code Online (Sandbox Code Playgroud)

...并且仍然成功调试项目.

当我将代码添加到构建服务器时,构建失败,说没有定义"var".

那么,我应该期待哪一个?

  1. VS2008,针对.NET 2.0,在我尝试做C#3时应该抛出错误
  2. 构建服务器,意识到我的目标是.NET 2.0,应该理解我正在做的事情并将事物编译成2.0兼容的二进制文件

有任何想法吗?

Jay*_*Jay 5

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. var is 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