I’m getting quite used to C# 3.0 and .Net 3.5 features. So it took some getting used to not being able to use ‘var’ and linq-to-objects when writing the ‘My book-pick’ widget for BlogEngine.Net you see on the right. Eventually I just gave up and hacked the Web.Config. It turned out to be really easy to switch BlogEngine.Net to C# 3.0.
First you have to set the compiler for the code-behind to .Net 3.5 (somehow the version numbers for .Net 3.5 and C# 3.0 are a bit mixed up, just ignore this and use the code I’m using here) You do this by adding this section to your web.config.
1: <system.codedom>
2: <compilers>
3: <compiler language="c#;cs;csharp" extension=".cs"
4: type="Microsoft.CSharp.CSharpCodeProvider,System,
5: Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
6: warningLevel="4">
7: <providerOption name="CompilerVersion" value="v3.5" />
8: <providerOption name="WarnAsError" value="false" /></compiler>
9: </compilers>
10: </system.codedom>
You need to add this just inside the <configuration> tag.
Now you’ll be allowed to use ‘var’ keywords and auto-properties. But of course we won’t stop until we have extension methods and linq.
Actually this is quite easy. Just add a reference to System.Code by adding this key to the <assemblies> section in <system.web>
1: <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Have fun coding your widget!