Automating Code Deployments to Azure Using TFS Online

Introduction

In this article, you will learn how to automate deployment of your Azure Web Site through Microsoft’s cloud-based Team Foundation Services (TFS) offering, also known as Visual Studio Online.

It is assumed that you already have the following:

  • A Microsoft Azure account with at least one Azure Web Site
  • A Visual Studio Online account—it is free for up to 5 users on unlimited projects—with at least one project
  • A local Visual Studio ASP.NET Web site solution

To automatically deploy your code to your Azure Web Site every time you check it in to Visual Studio Online, simple follow the steps below.

Step 1: Add Your Solution to Visual Studio Online

For this step, it is assumed that you already have an active connection to your Visual Studio Online account in your Visual Studio IDE. If this is not the case, go to the Team Explorer tab and make the connection. To see your changes, it might be useful to click the Source Control Explorer link once you make the connection.

Back on the Solution Explorer tab, right-click your solution and select Add Solution to Source Control. Accept the default selection of Team Foundation Version Control and click OK. Select the appropriate Team Project Location, change the name for the solution folder (if desired), and click the OK button.

In the Source Control Explorer tab, click the refresh button, and you should see that your solution is now added to the appropriate location in the project hierarchy. However, it has not yet been uploaded to Visual Studio Online. To do that, right-click the solution folder in the Source Control Explorer or the solution name in the Solution Explorer and select Check In Pending Changes. Enter some relevant text (for example, “Initial project upload to Visual Studio Online”, without the quotes) and click the Check-In button.

Your codebase / Web site has now been uploaded to Visual Studio Online.

Step 2: Set Up Automated Deployment

For this step, you will need to access your Azure Customer Portal.

In the Azure Portal, go to the homepage for your Azure Web App. Click the Dashboard tab. On the right-hand side of the user interface, you should see a Set up deployment from source control link. Click it.

Select Visual Studio Online and click Next (the small arrow in the bottom right of the dialog box). Enter your Visual Studio Online URL and click the Authorize Now link.

Click the Accept button. Then, choose the correct repository name and click the “Check” icon in the lower right. You will get a message that the link is being formed, which will change to “The team project is linked” when it is complete.

Step 3: Test Things Out

Before you test the deployment, browse to your Azure Web Site and verify that it is in whatever state it was in before you started this exercise.

Next, go back into your local Visual Studio IDE, make a change to the Web site, and then follow the procedure at the end of Step 1 to check in the code to Visual Studio Online.

Now, go back into your Azure Customer Portal and click the Deployments tab for your Azure Web Site. The process may take up to several minutes, but you will eventually see your first deployment literally happening right before your eyes.

Once the deployment is complete, go to your Azure Web Site in your browser and see your fresh changes.

Step 4: Rolling Back

Once you have a series of deployments on your Deployments tab for your Azure Web Site, and you have a brand new deployment that you do not like, you will want to roll back to the previous codebase.

The latest deployment should be at the top of the list and have the green Active Deployment designator. To roll the codebase back to the previous version, click the previous version in the list of Deployments and then click the Redeploy button at the bottom of the screen. Once complete, the previous deployment will have the green Active Deployment designator, and you should see the previous version when you browse to the Web site.

Conclusion

As you can see, the current Microsoft offerings make it very easy to not only move software development life cycle (SDLC) workloads to the cloud but also set them up to happen automatically. In this article, we have only shown one example, Deployment. With the same tools used in this article, you also can automate builds, testing, and just about anything else having to do with your SDLC. Be advised—the free version of Visual Studio Online has usage caps of 60 hours per month for build operations and 20,000 virtual user minutes per month for load testing… so it is fairly easy to incur charges once you start using these tools for real-world workloads.

We encourage you to use this article as a springboard to your continued learning about the nearly endless possibilities available through the Microsoft cloud offerings.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read