3

Looks as though dotnet CLI has no support for Database projects (.sqlproj) according to this: https://github.com/dotnet/sdk/issues/8546

in my case dotnet build fails with the following error:

C:...*.Database.sqlproj(59,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.301\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.301\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" is correct, and that the file exists on disk.

Needless to say, the solution compiles and generates .dacpac via Build in Visual Studio. I need this to work from command line. Do I have any solutions other than msbuild.exe? Perhaps some lovely nuget package out there that could help?

5
  • I think you can just download build tool for VS2019. It is a lightweight build tool that integrates various modules independently of VS. It's just a command tool. Commented Jun 24, 2020 at 7:15
  • which tool is it? Commented Jun 25, 2020 at 8:49
  • Build Tool for VS2019 Commented Jun 25, 2020 at 8:50
  • Build Tool for VS is more like the form of dotnet.exe and it is more suitable for you to build related projects on the build server. If you have any concern, please feel free to let us know:) Commented Jun 30, 2020 at 2:25
  • Any update for this in 2023? Commented Dec 3, 2023 at 2:39

3 Answers 3

3

I have managed to make it work as described in this article: https://erikej.github.io/efcore/2020/05/11/ssdt-dacpac-netcore.html

It requires a special type of .NET Standard Visual Studio project - MSBuild.Sdk.SqlProj (nuget download), which copies scripts from the Database project when compiled.

here's my build_database.cmd code:

SET db_project=Database.Build
dotnet tool install -g dotnet-script  
cd %db_project%
dotnet build
dotnet-script Program.csx 

And a C# script (Program.csx), which creates and deploys a .dacpac using Microsoft.SqlServer.DACFx nuget package:

#r "nuget: Microsoft.SqlServer.DACFx, 150.4769.1"
using Microsoft.SqlServer.Dac;

var dbName = "SampleDatabase";
var connectionString = $"Data Source=.;Initial Catalog={dbName};Integrated Security=True;";
var dacpacLocation = Directory.GetFiles(@".\bin", "Database.Build.dacpac", 
                                                           SearchOption.AllDirectories)[0];
var dbPackage = DacPackage.Load(dacpacLocation);
var services = new DacServices(connectionString);

services.Deploy(dbPackage, dbName, true); 

this approach is fully automated and can be used in either CI or local dev environment and, apparently, is also cross-platform (albeit I've only tested on Windows). Hope this helps :)

Sign up to request clarification or add additional context in comments.

Comments

0

Do I have any solutions other than msbuild.exe? Perhaps some lovely nuget package out there that could help?

Actually, there is no other build tool to build Database projects except msbuild.exe. So you have to use msbuild.exe.

Since VS2017, msbuild.exe has a separate version that does not depend on VS IDE called Build Tool for VS. And it is the build command line that integrates with the VS Workload environment.

So I think you want a lightweight build tool on build server rather than the huge VS IDE, if so, you should download it.

Suggestion

1) download build tool for VS2019 under All Downloads-->Tools for Visual Studio 2019-->Build Tool for Visual Studio 2019.

enter image description here

2) remember to select the corresponding workload Data storage and processing build tools

enter image description here

When you finish it, you can build your database project with it.

Comments

0

My method:

  1. Install Visual Studio Build Tools 2019

Include "Data storage and processing build tools" workflow and .NET Framework 4.6.1 targeting pack (individual component)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.