如何针对.NET 4.5与CSharpCodeProvider? [英] How to target .net 4.5 with CSharpCodeProvider?
问题描述
可能重复:结果
的使用CSharpCodeProvider与.NET 4.5 Beta版
块引用>
对于.NET 3.5我传递到v3.5版本CSharpCodeProvider,当我在V4.5的应用程序,我得到
出现InvalidOperationException
通V4.5到CSharpCodeProvider编译器可执行文件CSC.EXE无法找到。
任何人任何想法是怎么回事,我究竟做错了什么?
代码重现。 。
使用Microsoft.CSharp;
使用系统;
使用System.CodeDom.Compiler;
使用System.Collections.Generic;
命名空间控制台1
{
类节目
{
静态无效的主要(字串[] args)
{
变种选项=新字典<字符串,字符串> {{CompilerVersion,V4.5}};
变种CS =新CSharpCodeProvider(选件);
变种compilerParams =新CompilerParameters();
变种R = cs.CompileAssemblyFromSource(compilerParams,命名空间NS {类节目{公共静态的主要(字串[] args){的System.Console.WriteLine(\你好world\); }}});
}
}
}
解决方案这是由设计,东西的时候你导航到C可以看到:\windows\microsoft.net\framework与Windows资源管理器。请注意,您只看到一个名为的子目录v4.0.30319,没有V4.5子目录。或者换句话说,.NET 4.5是一个真正的就地更新4.0版和C#V5编译器的替换的V4的编译器。
你需要指定V4.0。
Possible Duplicate:
Using CSharpCodeProvider with .net 4.5 betaFor .net 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?
Code to reproduce . . .
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\"); } } }"); } } }
解决方案This is by design, something you can see when you navigate to c:\windows\microsoft.net\framework 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.
You'll need to specify "v4.0".
这篇关于如何针对.NET 4.5与CSharpCodeProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!