SSDT: Build in VSCode

Over the last couple of years I have been using VSCode more and more and Visual Studio less and less, this is great but there isn’t first class support for SSDT in VSCode, it would be great if there was but there isn’t today. This means I need to use Visual Studio to work with SSDT but often I find I just need to change a stored procedure or table and I don’t actually need the full SSDT experience, just a subset - can I change something and does it build, and can I deploy that build and run the tests?

So if I am just doing something simple then I have started using VSCode to edit an existing SSDT project and use a simple task runner to build the project, the task runner looks like this:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "${workspaceFolder}/sample-project/Sample/build.ps1",
            "options": {
                "cwd": "${workspaceFolder}/sample-project/Sample"
            },
            "args": [
                ],
            "group": "build",
            "presentation": {
                "reveal": "silent"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}

Note that my SSDT .SLN file is in “${workspaceFolder}/sample-project/Sample” - you need to put in whatever path you have.

Then I put a “build.ps1” file into my project that looks like:


if (!(Get-Command "msbuild.exe" -ErrorAction SilentlyContinue))
{ 
    $env:Path += "C:\Program Files (x86)\MSBuild\14.0\Bin";
}

msbuild

That is it, when I want to build I press “ctrl+shift+b” and choose “Build”.

Now be warned this is very limited, to add files I would need to edit the sqlproj file, to refactor I would need to manually edit the refactorlog so in reality I use this in conjuntion with SSDT but for 90% of a project it is editing and changing existing files so this actually works quite well.