开发者

Visual Studio 2008 Development Server uses C# 2.0 compiler

I have a test website with VS 2008 that just uses code behind files, such as Foo.aspx.cs. Thus, the web server 开发者_如何转开发compiles them on the fly. The problem I'm running into is I can't use any C# 3.0 features. If I do:

var x = 1;

or

public class Foo { public int x {get;set;} }

or

Foo x = new Foo() {x = 5};

Then VS will work fine (everything gets highlighted and Intellisensed), but when I run the site it just throws up compiler errors..

Is there a way to fix this, or do you have to compile a DLL to target the 3.0 runtime? If so that's insanely lame..

Mike


There is only the 2.0 runtime, there is no 3.0 or 3.5 runtime. They are just extra libraries and I believe a different C# compiler.

See http://www.novolocus.com/2008/01/11/net-framework-versions-language-versions-and-clr-versions-all-a-bit-fraught/

Are you sure the machine you are on has 3.0 or 3.5 installed? If it's local to the same machine that you have studio 2008 on then, it should.

Because you need the C# 3 compiler and the BCL, but the CLR version will still be 2.0.

So please provide the .net versions installed on the machine that IIS is running on.


Oh sweet, I got it figured out! I had to put this in the web.config..

   <system.codedom>
      <compilers>
         <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
                   type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="WarnAsError" value="false"/>
         </compiler>
         <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4"
                   type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="OptionInfer" value="true"/>
            <providerOption name="WarnAsError" value="false"/>
         </compiler>
      </compilers>
   </system.codedom>

I think this is because my web.config was borrowed from a very old project..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜