CodeDomProvider - Targeting .Net 3.5
If your using a CodeDomProvider to compile code yourself programmatically in VS 2008, what version of the Framework is targeted?
By default it is 2.0, irrespective of which VS 2008 target version (2.0, 3.0 or 3.5) is specified.
In order to target the 3.5 framework, provide an IDictionary<string,string> instance in the provider's constructor as shown below:-
var providerOptions = new Dictionary<string,string>();
providerOptions.Add("CompilerVersion", "v3.5");
CodeDomProvider compiler = new CSharpCodeProvider(providerOptions); // C# example
compiler = new VBCodeProvider(providerOptions); // VB example
Note that the dictionary contains an entry "CompilerVersion", "v3.5".
For C#, this is represented as something like the following in ASP.NET, and is what VS 2008 b2 inserts for you into the web.config file of each web app.
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
compilerOptions="/warnaserror-" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
</compiler>
</compilers>
</system.codedom>