'How to build .sqlproj projects using "dotnet" tool?

Unable to build .Net .sqlproj using "dotnet" command line tool. Here's the error:

dotnet\sdk\3.1.300\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found

I have installed SSDT tool but it's not available at the above location.

Note: It's buildings without any error using Visual Studio and MSBuild



Solution 1:[1]

How to build .sqlproj projects using “dotnet” tool?

Sorry but as I know this is not supported scenario for now. It's by design that dotnet cli can't build the Database Project with old-framework style project file.

As for the reason why it's buildings without any error using Visual Studio and MSBuild but failing using dotnet. Please check your SSDT installation path, it should be under pathC:\Program Files (x86)\Microsoft Visual Studio\2019\VSEditon\MSBuild\Microsoft\VisualStudio\v16.0\SSDT.

The SSDT is installed as a sub-module of MSBuild(VS build tools) or MSBuild from VS, so it works well when building it via VS/MSbuild. But dotnet cli won't know where to find this module which is under MSBuild folder's sub-folder, so it throws error.

There's once a discussion about this in github, in my opinion the feature to support build SQLProj via Dotnet hasn't come true. If you're interested in that feature, I suggest you can open a new ticket there to post your idea.

Solution 2:[2]

As of March 2020 this is now a possibility using the MSBuild.Sdk.SqlProj package. Technically it's not building the sqlproj file itself, but an equivalent version based on a csproj to produce a DACPAC. It currently has some advantages, such as cross-platform builds, and being able to build a whole folder instead of leaving out that one file that you always forget to manually add to the sqlproj. Current disadvantages are a slower build due to no dbmdl caching, and less IDE/tooling support at least for importing changes from an external database or DACPAC into the project source.

Solution 3:[3]

Some progress has been made, preview has been released https://github.com/microsoft/DacFx/tree/main/src/Microsoft.Build.Sql

<Sdk Name="Microsoft.Build.Sql" Version="0.1.3-preview" />

Solution 4:[4]

Microsoft has released SQL Database Project extension (preview) for compile using dotnet command

dotnet build "sqlproj file path" /p:NetCoreBuild=true /p:NETCoreTargetsPath="DotNet Core build folder"

https://docs.microsoft.com/en-us/sql/azure-data-studio/extensions/sql-database-project-extension-build-from-command-line?view=sql-server-ver15

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LoLance
Solution 2
Solution 3 holytshirt
Solution 4 Arun