首页 > 解决方案 > VS 2017,直接 CSharpCodeProvider 使用 C#7

问题描述

在我的 xcript 中实现 C#7 功能($- 字符串插值)并调用CSharpCodeProvider.CompileAssemblyFromSource()时,我收到以下错误:

E:\src\*****\****\bin\Debug> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" 
/t:library /utf8output /R:"E:\***\***\Main\ConsoleApp1\bin\Debug\***.dll" 
/R:"Microsoft.CSharp.dll" /R:"System.Core.dll" 
/R:"System.Data.DataSetExtensions.dll" /R:"System.Data.dll" 
/R:"System.Data.Linq.dll" 
/R:"System.dll" 
/R:"System.Xml.dll" 
/R:"System.Xml.Linq.dll" 
/R:"EntityFramework.dll" 
/out:"E:\***\***\Main\***RuleEngine\_DynamicDll\***RuleEngine.dll" 
/D:DEBUG /debug+ 
/optimize-  "E:\***\***\Main\***RuleEngine\_DynamicDll\TempFiles\5jdr2zw0.0.cs"
 Microsoft (R) Visual C# Compiler version 4.7.2558.0  for C# 5
 Copyright (C) Microsoft Corporation. All rights reserved.
 This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
 E:\***\***\Main\***RuleEngine\_DynamicDll\TempFiles\5jdr2zw0.0.cs(549,35): error CS1056: Unexpected character '$'

 0) E:\***\***\Main\***RuleEngine\_DynamicDll\TempFiles\5jdr2zw0.0.cs(549,35) 
 : error CS1056: Unexpected character '$'

建造:

_csc = new CSharpCodeProvider(new Dictionary<string, string>() { { 
"CompilerVersion", "v4.0" } });

知道如何解决这个问题吗?

谢谢!

标签: c#csharpcodeprovider

解决方案


推荐阅读