CSharpCodeProvider pulls .NET 2.0 assembly from .NET 4.0 application

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

+3
source share
1 answer

You can provide the compiler version as an option through the CSharpCodeProvider constructor, which takes a providerOptions (IDictionary) argument. If you use CodeDomProvider.CreateProvider, you can use its similar overload. eg:.

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

. . http://msdn.microsoft.com/en-us/library/bb537926.aspx.

+5

Source: https://habr.com/ru/post/1765373/


All Articles