我有一个问题,CodeDom编译器是否可以使用x64位或x86位等自定义配置来编译c#代码。默认情况下,它将使用“任何CPU”配置将c#代码编译为.exe。 编译C#代码:
public static string BCS(string[] sources,string[] libs,string outPath,bool exef)
{
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters(libs);
parameters.GenerateExecutable = exef;
parameters.OutputAssembly = outPath;
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, sources);
if (results.Errors.Count > 0)
{
string errsText = "";
foreach (CompilerError CompErr in results.Errors)
{
errsText = "("+CompErr.ErrorNumber +
")Line " + CompErr.Line +
",Column "+CompErr.Column +
":"+CompErr.ErrorText + "" +
Environment.NewLine;
}
return errsText;
}
else
{
return "Success";
}
}
我认为,您了解我的问题,如果没有,请发表评论,我会提供详细信息。
答案 0 :(得分:0)
尝试以此方式设置CompilerOptions
parameters.CompilerOptions = "-platform:anycpu32bitpreferred";
使用此链接中的参数
P.S。 CSharpCodeProvider
使用csc.exe