views:

37

answers:

2

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

+1  A: 

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.

Tim Hoolihan
The machine definitely has 3.5 installed because I'm compiling DLLs with 3.5 synax (LINQ and stuff).. This error only happens when WebDev.exe compiles a code behind page.. As I mentioned, IIS is not installed on this machine. I'm trying to figure out how to make WebDev.exe use the 3.0 compiler.
Mike
FYI, the "Target Framework" in the property pages "Build" tab is set to ".NET Framework 3.5"..
Mike
Got it figured out, there's a thing in the web.config that tells WebDev what compiler to use..
Mike
A: 

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

Mike