我在使用 Visual Studio 2015 编译 SSDT SQL Server 数据库项目时遇到问题。我想在我的数据库项目中使用 C# 6 功能,但它似乎不受支持。
例如,我在我的数据库项目中添加了下一个类:
namespace Database1
{
class ClassFile1
{
public string Str { get; } = string.Empty;
}
}
我尝试编译这个,但出现错误:
CS1519:类、结构或接口成员声明中的标记“=”无效
我发现这个错误的原因是VS 2015使用的编译器版本错误。下一个编译行是由VS生成的:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll" /debug+ /debug:full /optimize- /out:obj\Debug\Database2.dll /subsystemversion:6.00 /target:library /warnaserror- /utf8output ClassFile1.cs
可以看到,使用的是C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe,是错误的。
我尝试从 VS 2015 的开发人员命令提示符编译 db 项目,并且成功完成,因为在这个提示符中 csc.exe 是 Roslyn 编译器 (C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe)支持 C# 6 功能。你可以检查问题如何从命令行运行 Roslyn 而不是 csc.exe?
我尝试使用 MSBuild 14.0 编译该项目,也成功完成。
问题是:如何更改/覆盖我的 VS 用于编译 SSDT DB 项目的编译器版本,从旧的 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe 更改为新的 Roslyn 编译器(C: \Program Files (x86)\MSBuild\14.0\Bin\csc.exe)?