私は最近Visual Studio 11 Betaをインストールしましたが、4.5を使用するように既存の4.0プロジェクトを更新しようとしています。プログラムでは、CSharpCodeProvider
を使用して動的に生成されたコードをコンパイルします。 CSharpCodeProviderを.net 4.5ベータで使用する
/// <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", "v4.5" }
に{ "CompilerVersion", "v4.0" }
からCompilerVersion
を変更したときに、私は今
コンパイラの実行可能ファイルcsc.exeが見つからない例外を取得しています。
CompilerVersion
を指定すると間違った方法で4.5を使用するように指定されていますか?コードが新しい4.5固有の機能を使用しないので、それをv4.5としてコンパイルすると違いが生じますか?
私はそのようなコンパイラのバージョンを指定することが間違っている場合は知っているが、FWIWません.NET 4.5でのコンパイラは、出力に応じて、まだバージョン4.0です。 –
なぜ最初のエラーのみを返すのですか? – abatishchev
@abatishchev私がコンパイルしているコードはすべて自動生成されているので、テンプレートが乱れない限り、通常はエラーが発生しません。最初のコードを返すだけで何千ものエラーが返されることを防ぎます。電子メールでもう役に立ちません。 – BrandonAGr