【发布时间】:2015-10-08 09:24:53
【问题描述】:
我在使用 Visual Studio 2015 编译 SSDT SQL Server 数据库项目时遇到问题。我想在我的数据库项目中使用 C# 6 功能,但似乎不受支持。 例如,我在我的 db 项目中添加了下一个类:
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 功能。您可以查看问题How to run Roslyn instead csc.exe from command line?
我尝试使用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)?
【问题讨论】:
标签: c# .net msbuild visual-studio-2015 sql-server-data-tools