Deploy an ASP.NET MVC Web Application to Azure Website using Release Management for TFS

There are a lot of articles about the integration of an Azure VM into Release Management for TFS. What if you simply want to deploy an ASP.NET MVC application without the need to provision a dedicated machine.
It turns out to be quite simple. One of the most efficient way to do it is to create the initial deployment from Visual Studio and then pick up the piece to build a RM template.

My Web Application is quite simple: a database, a Entity Framework Code First model all sitting inside the ASP.NET MVC application. Like all deployments, the main process is:
- generate the Web Deploy Package with placeholders for configuration (connection string, parameters, etc.) using TFS Build (or whatever build system you have).
- Deploy to the staging machine (using a agent-based or agent-less machine)
- Run the MS Deploy CMD file with the appropriate parameters to trigger the deployment on Azure.

The reason I use a staging machine as the basis for the CMD is that it allows me to restrict the firewall configuration to one single machine from which all deployments to Azure will happen.

If you need guidance on the generation of the Web Deploy package, you can refer to the following article as a starting point.
The main difference in my approach is that the component I create to deploy to Azure is no longer based on IRMSDeploy.exe. It is a simple "Windows Command Line Processor" based component.

Details of the component to publish to Azure
Details of the component to publish to Azure

The complete command line arguments are:

/C ""__WebApplicationName___Package\__WebApplicationName__.Deploy.cmd" /Y "/m:__AzureDeployUrl__?Site=__SiteName__" -allowUntrusted /u:"__Username__" /p:"__Password__" /a:Basic"

The __WebApplicationName__ parameter can be customized dependending on your own publish parameter. The other parameters represent values taken from the publish profile that you need to retrieve from the Azure portal (by clicking on "Download the publish profile").
Azure Portal to retrieve the PublishSettings file
Azure Portal to retrieve the PublishSettings file

The table below describe how to retrieve the parameter values.

Parameter Value
SiteName Look for tag "msdeploySite" in the PublishSettings file
AzureDeployUrl Usually
Username Look for tag "userName" in the PublishSettings file
Password Look for tag "userPWD" in the PublishSettings file

Once you have all the information, you just need to update the release template with your component. In the screenshot below, there are some additional parameters. There are only relevant for the application I am publishing, you can safely ignore the EnvironmentName and Database-ConnectionString (though they are very likely to be part of your own deployment component).
Details of the release template using the custom component
Details of the release template using the custom component

When this is done, you can test the release by triggering a build (or a release directly) and see if it works.

Feel free to drop a comment if you need help!

Note: you might encounter the following error in the deployment log:
More Information: Creating a new application is not supported by this server environment.

This is most likely due to an incorrect value in the publishing parameters (DeployIisAppPath in that case). Open your publish profile in Visual Studio.
Publish profiles in Visual Studio
In the XML file, make sure the value for DeployIisAppPath will render exactly as the value for "msdeploySite" taken from the Azure PublishSettings files.
Value for the DeployIisAppPath

 In our case, the value will be replaced by the RM engine as defined in the component created earlier. Actually, this is how we link the Azure Website with the content of the Web Deploy package.

Popular posts from this blog

Adding a delay before processing Textbox events

Handling exceptions the right way in WCF (part 2)

Create a draft release and start it using the TFS REST API