May 17, 2013

Deploy SSDT SQL Project using Post-build event command line

I recently started working on a project with an SQL 2012 server database project. To target SQL 2012 I had to install SQL Server Data Tools or SSDT. If you haven't already had a chance to look into SSDT then you may not know that with SSDT .dbproj files (Visual Studio Database Projects) have been replaced by .sqlproj files (SQL Database Projects). The new project file type allows you to target all SQL server versions including 2012. Sqlzapper did a nice post on the key differences between the two and helped me understand better how builds and deployments work with in SSDT.

With Visual Studio Database Projects you could use VSDBCMD.EXE to deploy your database project using the Post-build event command line in your project properties.

[caption id="attachment_410" align="alignnone" width="701"]Database Project Post-build command line Database Project Post-build command line[/caption]

So, I needed to figure out how to do this with SQL Projects as my build was failing miserably doing the way you would with Database Projects. The docs on MSDN tell you how to publish a database project using the 'Publish Database' dialog (like one-click publish). Although this method works its not ideal in situations were you want to automate your publish on build to satisfy some dependencies, or if your lazy and don't want to right-click and deploy each time ;) Unfortunately, I couldn't find how to automate the publishing of the database. After reading sqlzapper's post I realized that I needed to use SQLPACKAGE.EXE to publish my database in the Post-build event command line instead of VSDBCMD.EXE.

[caption id="attachment_411" align="alignnone" width="701"]SQL Project Post-build command line SQL Project Post-build command line[/caption]

You can find more information on SQLPACKAGE.EXE commands at http://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx.

I just showed you how to deploy your database using the Post-build command line. Looking at the images there is a lot to be explained, such as the new tabs in the project properties and .dbschema file extension from the database project vs. the .dacpac file extension from the SQL database project (in the Post-build event scripts). Check out sqlzapper's post and the other links I provided above to learn more about them.

No comments:

Post a Comment