Tuesday 28 July 2015

Deploy Azure DB via Web App – Using VS 2013 Release Management – Part 1 – Package SQL dacpac with Web Deploy Package in TFS Build

As explained in the post “How to Deploy to Azure Websites with TFS build 2013 and VS Release Management 2013” a tool can be created in VS 2013 Release management to deploy web sites to Azure. Below are the steps to deploy a azure database with the web application, using the same tool (enhanced to handle database deployments).
In the solution taken for as example a Web application project and a Database project created.
1
For demo purpose one table added to the database and created in localdb (db server provided with Visual Studio).
2
3
4
5
6

This database is added to the Web Application project by defining a connection string in the web.config file.
7
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).
8
Once this is published the required deployment packages created.
9
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.
10
In order to get the .dacpac file to web package change the publish profile (pubxml) content as shown below.
Current
11
Changes highlighted.
  • 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.
12
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.
16
With the above change when the web application is published as a web deploy package, the .dacpac file gets included in it.
13
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.
/p:CreatePackageOnPublish=true /p:DeployOnBuild=true;PublishProfile="TFSAzureRelease"
14
As expected FS build fails with error, unable to find .dacpac file.
15
By changing the publish profile relative path to .dacpac file as below as will give a successful build.
17
18

Web deployment package in the drop now contains the .dacpac file.
20
Set parameter xml is created with the tokens added for DB connection.
19
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.

No comments:

Popular Posts