1

I have a .sqlproj (Microsoft SQL Project) folder (Git repository) which I'd like to Publish to a live database instance using command line tools.

My colleague currently does this manually using Visual Studio:

  1. Right-click on Solution then select Rebuild solution
  2. Right-click on database project then select Publish
  3. Load a profile from a .XML file (containing database connection string and a few other options)
  4. Hit Publish to build this database on to the server specified in .XML file

How can I replicate this using command line tools? Preferably I would use Linux, but I'm open to using Windows options too as long as the process is fully automated.

Thanks in advance

turbonerd
  • 1,234
  • 4
  • 27
  • 63
  • The CLI is [`sqlpackage.exe`](https://learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage), available for Windows and Linux. – Dan Guzman Apr 27 '21 at 14:36
  • @DanGuzman does this work from a SQL Project? I'm looking at your link and all of its commands appear to work on an existing live database - which I don't have. – turbonerd Apr 27 '21 at 14:42
  • It uses the dacpac build artifact from the db project build. You need to first build the project, which can be done from the command-line (e.g. msbuild). – Dan Guzman Apr 27 '21 at 15:00
  • That's what I'm asking - what tools do I need to replicate the above process. If you're saying `msbuild` to create a DACPAC, then `sqlpackage` to publish this DACPAC to a live instance - great. Do you have any decent documentation for `msbuild`? – turbonerd Apr 27 '21 at 15:02
  • I wouldn't go so far as to say it's decent but you might peruse the [msbuild documentation](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild). It seems it can also invoke the DacFx API directly instead of calling sqlpackage per [this answer](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild). – Dan Guzman Apr 27 '21 at 16:27

0 Answers0