Friday, March 12, 2010

Web Sites and the CodeDom

If you are using a WebSite (as opposed to Web Application project), and upgrade to .Net 3.5 (so you can use features like LINQ), you will need to add the following config section to your web.config:

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

<provideroption value="false" name="WarnAsError">
</compiler>
</compilers>
</SYSTEM.CODEDOM>

This of course is for both C# and VB, you can remove the non-used language section. The reason this is needed is that when you have a website, individual pages are compiled when requested, which requires the CodeDom to know which version of the framework you want to use. If you use a Web Application project this setting is not needed since an assembly is pre-compiled for all pages in your project.

No comments:

Post a Comment