3

I'm using the CSharpCodeProvider to compile a CodeDom object into an assembly. The application itself is running under .NET 4.0. However I need the output from CompileAssemblyFromDom to build against .NET 2.0 for compatibility with some external resources. How can I tell the CSharpCodeProvider to build against .NET 2.0?

1 Answer 1

5

You can provider the compiler version as an option via the CSharpCodeProvider constructor that takes a providerOptions (IDictionary) argument. If you're using CodeDomProvider.CreateProvider, you can use its similar overload. e.g.:

using (CodeDomProvider provider = CodeDomProvider.CreateProvider(
    "CSharp",
    new Dictionary<string, string>() { { "CompilerVersion", "v2.0" } }))
{
    //...
}

The compiler version can also be specified via a configuration file. See http://msdn.microsoft.com/en-us/library/bb537926.aspx for details and examples.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.