Search code examples
c#.netmsbuildvisual-studio-2015sql-server-data-tools

Usage of wrong compiler during SQL Server Database Project building


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: Invalid token '=' in class, struct, or interface member declaration

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 

As you can see, C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe is used and it is wrong.

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?

I tried to compile the project by using MSBuild 14.0 and it was successfully done too.

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)?


Solution

  • 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