Using Web Deploy with Windows Azure for Rapid Development

Dec 17, 2010

Update: Ryan Dunn has just posted Using Web Deploy with Windows Azure that shows a way to use plugins to simplify the process of using Web Deploy with Windows Azure. He also provides a lot of nice commentary and context around the solution. Definitely worth reading.

While building your web application, have you ever deployed to Windows Azure and then realized you forgot to make a change? Or forgot to include an update? Or maybe you deployed and realized you made a simple mistake, and you want to quickly update it? We all have. You’ll then find yourself making the change, creating a new package, and uploading/deploying it. Then you wait.

Now, in the grand scheme of things, waiting 10 minutes is not a big deal – think about everything you’re getting that you don’t already have at your disposal. That said, during development and QA, it can be frustrating to have to wait while your role instance upgrades or restarts.

Fortunately, with the updates provided in the Windows Azure SDK 1.3, we can benefit from an existing technology called Web Deploy to make our lives much easier.

A few caveats first:

This technique should only be used for development purposes.

You can only update a single role instance with this technique.

Since you are not updating the Windows Azure package you may lose your changes at anytime.

Be sure and understand the above caveats. This is only for development purposes.

Okay, ready to get started? Here are the steps to follow.

Create a new Windows Azure Project called WindowsAzureWebDeploy. Add an ASP.NET MVC 2 Web Role called MvcWebRole to the solution. It’s up to you if you want a unit test project.

Created a folder called Startup in your MvcWebRole project.

Create three files in this folder: CreateUser.cmd, EnableWebAdmin.cmd, and InstallWebDeploy.cmd. For each of these files, change the Copy to Output Directory value to Copy always and the Build Action value to Content.

Update (12/21/2010): I have made a few updates above to the scripts based on feedback and testing.

At this point, you are ready to deploy your application. When the role instance starts-up, the three start-up tasks will run and 1) create an user, 2) install web deploy through the Web Platform installer, and 3) enable web administration. This process can take several minutes to complete.

Once deployed, your application should look like this:

Now it’s time to setup your MvcWebRole project to publish directly to your role instance through web deploy. First, though, make a quick change to your application so that, after you deploy, you can verify that the new bits are deployed.

After you get the message Publish succeeded, refresh your page. It should now look like this:

And there you have it! Within seconds you’ve deployed updates to your application running in Windows Azure.

Now, do you remember the caveats above? If nothing else, remember that this is only for development purposes. I don’t want to hear that you used this in production then lost all your changes when a role instance was restarted.