我最近安装了 Visual Studio 11 Beta,我正在尝试更新现有的 4.0 项目以使用 4.5。在程序中,它使用CSharpCodeProvider
.
/// <summary>
/// Compile and return a reference to the compiled assembly
/// </summary>
private Assembly Compile()
{
var referencedDlls = new List<string>
{
"mscorlib.dll",
"System.dll",
"System.Core.dll",
};
referencedDlls.AddRange(RequiredReferences);
var parameters = new CompilerParameters(
assemblyNames: referencedDlls.ToArray(),
outputName: GeneratedDllFileName,
// only include debug information if we are currently debugging
includeDebugInformation: Debugger.IsAttached);
parameters.TreatWarningsAsErrors = false;
parameters.WarningLevel = 0;
parameters.GenerateExecutable = false;
parameters.GenerateInMemory = false;
parameters.CompilerOptions = "/optimize+ /platform:x64";
string[] files = Directory.GetFiles(GenerationDirectory, "*.cs");
var compiler = new CSharpCodeProvider(
new Dictionary<string, string> { { "CompilerVersion", "v4.5" } });
var results = compiler.CompileAssemblyFromFile(parameters, files);
if (results.Errors.HasErrors)
{
string firstError =
string.Format("Compile error: {0}", results.Errors[0].ToString());
throw new ApplicationException(firstError);
}
else
{
return results.CompiledAssembly;
}
}
当我将CompilerVersion
from更改{ "CompilerVersion", "v4.0" }
为{ "CompilerVersion", "v4.5" }
我现在得到一个例外
找不到编译器可执行文件 csc.exe。
是否指定CompilerVersion
了错误的方式来告诉它使用 4.5?由于代码不会使用任何新的 4.5 特定功能,因此将其编译为 v4.5 是否会产生影响?