如何针对.NET 4.5与CSharpCodeProvider?

编程入门 行业动态 更新时间:2024-10-22 13:36:07
本文介绍了如何针对.NET 4.5与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\framework与Windows资源管理器。请注意,您只看到一个名为的子目录v4.0.30319,没有V4.5子目录。或者换句话说,.NET 4.5是一个真正的就地更新4.0版和C#V5编译器的替换的V4的编译器。

你需要指定V4.0。

Possible Duplicate: Using CSharpCodeProvider with 4.5 beta

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?

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\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?

本文发布于:2023-11-12 20:28:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582457.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   CSharpCodeProvider

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!