Using .Net 3.5 features in BlogEngine.Net widgets

30. June 2009

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!

Comments

7/13/2009 3:51:24 PM

Muiden

Nice post! I have added your feed to Google Reader!

Muiden United Kingdom

7/14/2009 3:07:02 PM

Michael

Thanks a lot for this post

Michael Denmark

7/21/2009 8:03:05 AM

Soft Pay Systems

Thanks for sharing this information. I really appreciate your post.

Soft Pay Systems

Soft Pay Systems United States

Comments are closed

Powered by BlogEngine.NET 1.5.0.7
Theme adapted from BlogEngine.NET standard theme by Mads Kristensen

Mendelt Siebenga

Mendelt Siebenga with coffeeMendelt Siebenga works as a C# programmer. In his spare time he's been known to pick up Python, Lisp and even a soldering iron from time to time.

You can also find me here