简体   繁体   English

CSharpCodeProvider从.NET 4.0应用程序输出.NET 2.0程序集

[英]CSharpCodeProvider output .NET 2.0 assembly from .NET 4.0 application

I'm using the CSharpCodeProvider to compile a CodeDom object into an assembly. 我正在使用CSharpCodeProvider将CodeDom对象编译为程序集。 The application itself is running under .NET 4.0. 应用程序本身在.NET 4.0下运行。 However I need the output from CompileAssemblyFromDom to build against .NET 2.0 for compatibility with some external resources. 但是,我需要CompileAssemblyFromDom的输出来针对.NET 2.0进行构建,以便与某些外部资源兼容。 How can I tell the CSharpCodeProvider to build against .NET 2.0? 如何告诉CSharpCodeProvider针对.NET 2.0构建?

You can provider the compiler version as an option via the CSharpCodeProvider constructor that takes a providerOptions (IDictionary) argument. 您可以通过CSharpCodeProvider构造函数提供编译器版本作为选项,该构造函数采用providerOptions(IDictionary)参数。 If you're using CodeDomProvider.CreateProvider, you can use its similar overload. 如果您正在使用CodeDomProvider.CreateProvider,则可以使用其类似的重载。 eg: 例如:

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. 有关详细信息和示例,请参阅http://msdn.microsoft.com/en-us/library/bb537926.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM