如何使用 CSharpCodeProvider 定位 .net 4.5?

编程入门 行业动态 更新时间:2024-10-26 00:27:51
本文介绍了如何使用 CSharpCodeProvider 定位 4.5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能的重复:在 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?

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

发布评论

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

>www.elefans.com

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