In the solution taken for as example a Web application project and a Database project created.
For demo purpose one table added to the database and created in localdb (db server provided with Visual Studio).
This database is added to the Web Application project by defining a connection string in the web.config file.
In the publish profile (for details on creating a publish profile for the web application refer the article here) database connection should be defined as a token understandable by the VS 2013 Release Management (__ as prefix and suffix).
Once this is published the required deployment packages created.
But the .dacpac file to deploy the db is not added to the web package zip file. It is required to get .dacpac inside the web package to deploy it with web application deployment.
In order to get the .dacpac file to web package change the publish profile (pubxml) content as shown below.
- DB Connection object group enabled.
- Default created “DbDacFx” object type is disabled.
- Added new “DbDacFx” with dacpacAction Deploy and path set to relative path of the .dacpac file being built for the SQL project. Note that bin\debug path is set here which is not going to work with TFS builds.
Then there should be a project dependency added to build the SQL project before the web application project to make sure the availability of .dacpac file.
With the above change when the web application is published as a web deploy package, the .dacpac file gets included in it.
The next step is to get this packaged via TFS builds. As explained in the article here TFS build can be setup for this purpose with build arguments specified below.
As expected FS build fails with error, unable to find .dacpac file.
By changing the publish profile relative path to .dacpac file as below as will give a successful build.
Web deployment package in the drop now contains the .dacpac file.
Set parameter xml is created with the tokens added for DB connection.
In Part 2 let’s look at how to enhance the release management component, to deploy web application package (explained in article here), with the database .dacpac file to Azure DB.