In this blog post I will share my experience in how to deploy database project from msbuild using command line and VS2010 and SQL Server 2008 R2. I started with Microsoft site How to: Deploy Changes to New or Existing Databases obviously I didn't read it as I wanted to quickly deploy my very own database project (with just one table) and not become an expert in every single scenario.
I learnt that I should open command line tool and use msbuild.exe using something like that "MSBuild /t:Build;Deploy DatabaseProject.dbproj"
I opened cmd tool and typed cd C:\MyFolder where MyFolder is that path of the database project solution. I typed the command and came across the first problem? It didn't locate MSBuild.exe tool and gave me the following error
'MSBuild.exe' is not recognized as an internal or external command, operable program or batch file
As I am not an expert in this and didn't want to read several pages Microsoft document I decide to make a shortcut so I tried window search but for some reason it didn't find it? I did quick Google search and I was able to find the file in this location "C:\Windows\Microsoft.NET\Framework\v4.0.30319"
I changed msbuild.exe to full location with quotes "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" and that worked but for some reason it didn't deploy the solution? I did a quick check of database project properties and found an option that has two option under Deploy Action one is to create only a deployment script (without running it) and second one is to create deploy script and run it on the selected database which is what I changed it to.
Below is screenshot of the change I made.
After this change I tried again my msbuild.exe deploy and this time deploy actually deployed the project! And it worked! Below is the final command I used and end results
For comprehensive explanation of how to deploy database project using msbuild visit Microsoft page.