.netmsbuilddatabase-project

Publish database project using MsBuild


I have a database project in my solution. It comes with the Local.Datatabase.publish.xml. After building the project, if I double click on the xml file, I'm able to publish the changes to my local database.

I like to automate this process. Using MsBuild, I like to be able to do the same thing.

I've set $msbuild to C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

Unfortunately, $msbuild /t:Publish /p:SqlPublishProfilePath="Local.Database.publish.xml" isn't working.

How can I publish a database project using MsBuild?


Solution

  • The database projects create bacpac files after build. I can use the sqlpackage, and funnel the connection string in as the parameter.

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\120\SQLPackage.exe" /a:Publish /TargetConnectionString:"Data Source=(local); Initial Catalog=Database; Integrated Security=SSPI;" /SourceFile:"D:\project\bin\Debug\projectname.dacpac"
    

    enter image description here