Usage of wrong compiler during SQL Server Database Project building

与世无争的帅哥 提交于 2019-12-01 21:28:17

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 2012 = CLR 4

You can't just run any version of the clr that is on the machine I am afraid.

ed

I was trying to do this as well and faced the same problem. My workaround is to create a separate regular class library project. I moved the C# code from my Database project into the new library (which will be compiled using C# 6/Roslyn by VS 2015). And then reference this class library from my Database project.

Just remember to set the properties of the reference to the class library: Model Aware=true and Generate Sql Script=true. I haven't tested this thoroughly, but I was able to deploy it from my Database project by using the publish command, and call the function inside the class library.

Good news!
Visual Studio 2017 will use the current C# compiler for SSDT Database Projects, so all the features of
C# 6 will finally work in SQL Server assemblies.

The path of the used compiler is:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\csc.exe

Because all of the C# 6 features are just pure compiler features you can now even use them if you are only targeting .NET 3.5 and SQL Server 2008.

In Visual Studio 2017 RC, I was also able to use some C# 7 features like expression bodied constructors, the new out variables, ref returns, the enhanced switch/is pattern matching and the improved binary/hex literals. But I was unable to use local functions or anything related to tuples like the new tuple return types, tuple literals or the new deconstruction declaration.
Maybe this behavior will change in the final release of Visual Studio 2017.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!