可能的重复:在 4.5 beta 中使用 CSharpCodeProvider
对于 3.5,我将 v3.5 传递给 CSharpCodeProvider,当我在 v4.5 应用程序中将 v4.5 传递给 CSharpCodeProvider 时,我得到 InvalidOperationException找不到编译器可执行文件 csc.exe."
For 3.5 I pass v3.5 to CSharpCodeProvider, when I pass v4.5 to CSharpCodeProvider in a v4.5 app I get InvalidOperationException "Compiler executable file csc.exe cannot be found."
有人知道这里发生了什么吗,我做错了什么?
Anyone any idea what's going on here, what am I doing wrong?
代码重现...
using Microsoft.CSharp; using System; using System.CodeDom.Compiler; using System.Collections.Generic; namespace Console1 { class Program { static void Main(string[] args) { var options = new Dictionary<string, string>{{"CompilerVersion", "v4.5"}}; var cs = new CSharpCodeProvider(options); var compilerParams = new CompilerParameters(); var r = cs.CompileAssemblyFromSource(compilerParams , "namespace ns { class program { public static Main(string[] args) { System.Console.WriteLine("Hello world"); } } }"); } } } 推荐答案这是设计使然,当您使用 Windows 资源管理器导航到 c:windowsmicrosoftframework 时可以看到这些内容.请注意,您只会看到名为 v4.0.30319 的子目录,没有 v4.5 子目录.或者换句话说,.NET 4.5 是 4.0 版的真正就地更新,C# v5 编译器取代了 v4 编译器.
This is by design, something you can see when you navigate to c:windowsmicrosoftframework with Windows Explorer. Note that you'll only see a subdirectory named v4.0.30319, there is no v4.5 subdirectory. Or in other words, .NET 4.5 is a true in-place update for version 4.0 and the C# v5 compiler replaces the v4 compiler.
您需要指定v4.0".
You'll need to specify "v4.0".
更多推荐
如何使用 CSharpCodeProvider 定位 .net 4.5?
发布评论