最近、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
からに変更したときに問題が発生{ "CompilerVersion", "v4.0" }
します{ "CompilerVersion", "v4.5" }
私は今例外を取得します
コンパイラの実行ファイル csc.exe が見つかりません。
CompilerVersion
4.5を使用するように指示する間違った方法を指定していますか? コードは新しい 4.5 固有の機能を使用しないため、v4.5 としてコンパイルしても違いはありますか?