对于.net 3.5我将v3.5传递给CSharpCodeProvider,当我在v4.5应用程序中将v4.5传递给CSharpCodeProvider时,我得到InvalidOperationException"无法找到编译器可执行文件csc.exe".
任何人都知道这里发生了什么,我做错了什么?
代码重现...
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\"); } } }");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图使用next命令在powershell中编译C#源代码:
Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $source
Run Code Online (Sandbox Code Playgroud)
但是C#6.0功能不起作用,例如:
new Problem($"... ({identifier})", node)
Run Code Online (Sandbox Code Playgroud)
代码:
Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $source
Run Code Online (Sandbox Code Playgroud)
我正在使用最新的PowerShell Add-Type : c:\Users\...\AppData\Local\Temp\2\d2q5hn5b.0.cs(101) : Unexpected character '$'
有没有办法来解决这个问题?