在SQL Server数据库项目构建过程中使用错误的编译器 [英] Usage of wrong compiler during SQL Server Database Project building
问题描述
我使用Visual Studio 2015编译SSDT SQL Server数据库项目时遇到问题.我想在数据库项目中使用C#6功能,但似乎不受支持. 例如,我在数据库项目中添加了下一个类:
I have an issue with compilation of SSDT SQL Server Database Project by using Visual Studio 2015. I want to use C# 6 features inside my database project, but it seems like it is unsupported. For example, I have added the next class in my db project:
namespace Database1
{
class ClassFile1
{
public string Str { get; } = string.Empty;
}
}
我尝试编译它,但是出现错误:
I have tried to compile this, but I got the error:
CS1519:类,结构或接口成员声明中的无效令牌'='
CS1519: Invalid token '=' in class, struct, or interface member declaration
我发现此错误的原因是VS 2015使用的编译器版本错误.下一个编译行由VS生成:
I have found out that the reason of this error is wrong version of compiler that used by VS 2015. The next compilation line is generated by 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,这是错误的.
As you can see, C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe is used and it is wrong.
我已尝试从VS 2015的开发人员命令提示符处编译db项目,此操作已成功完成,因为在此提示符下csc.exe是Roslyn编译器(C:\ Program Files(x86)\ MSBuild \ 14.0 \ Bin \ csc. exe)支持C#6功能.您可以检查问题如何运行Roslyn而不是csc.exe从命令行?
I have tried compile db project from Developer Command Prompt for VS 2015 and this was done successfully, because inside this prompt csc.exe is Roslyn compiler (C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe) that support C# 6 features. You can check question How to run Roslyn instead csc.exe from command line?
我尝试使用MSBuild 14.0编译项目,并且它也成功完成了.
I tried to compile the project by using MSBuild 14.0 and it was successfully done too.
问题是:如何将我的VS用来编译SSDT DB项目的VS版本从旧的C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Csc.exe更改/改写为新的Roslyn编译器(C:\ Program Files(x86)\ MSBuild \ 14.0 \ Bin \ csc.exe)?
The question is: how can I change/override version of compiler that my VS used for compilation of SSDT DB project from old C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe to new Roslyn compiler (C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe)?
推荐答案
您需要定位将要部署到的SQL版本所使用的clr版本:
You will need to target the version of clr that is used by the version of SQL that you will be deploying to:
SQL 2005-2008 R2 = CLR 2
SQL 2005-2008 R2 = CLR 2
SQL 2012 = CLR 4
SQL 2012 = CLR 4
恐怕您不能只运行计算机上任何版本的clr.
You can't just run any version of the clr that is on the machine I am afraid.
编辑
这篇关于在SQL Server数据库项目构建过程中使用错误的编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!