Deploy your ASP.NET app to an Azure web site

Last Update: 2/23/2017

Team Services | TFS 2017 | TFS 2015 | Previous versions (XAML builds)

Continuous deployment means starting an automated deployment process whenever a new successful build is available. Here we'll show you how to set up continuous deployment of your ASP.NET app to an Azure web site using Release Management.

Are you new to our product? If so, see

Get set up

Begin with a CI build

Before you begin, you'll need a CI build that publishes your Web Deploy package. To set up CI, see:

Create the Azure app service

An Azure App Service is where you'll deploy your application. Technically speaking, an app service is a resource with a specific pricing tier in Azure that can then host multiple, distinct applications. In this example we'll use a Web App. If you're creating a new App Service for this example, you can use the Free pricing tier.

To create a new Web App, simply go to the App Services blade on the Azure portal, click +Add, select the Web App template, click Create, and enter a name and other details. The web app URL will then be {name}.azurewebsites.net.

Can I use an existing Azure account? ▼

If you have an existing Azure account, you can certainly use a new or existing App Service in that account for this walkthrough.

How do I create a new Azure account with free credits? ▼

If you don't yet have an Azure account, you can get started with free credits at https://azure.microsoft.com/en-us/free/. Alternately, consider signing up for Visual Studio Dev Essentials which gives you $25/month in Azure credit each month for a full year.

Can I just use a temporary App Service instead? ▼

Yes, just visit Create your Azure App Service App to set up a Web App for temporary use (1 hour). On that page, do the following:
  1. Select Web App and choose Next.
  2. Select Empty Site and choose Create (we use an empty site because you already have the necessary application code in your Visual Studio project).
  3. Enter your Microsoft account credentials when requested.
In a few moments the site will then give you a URL such as https://df8381c9-0ee0-4-aaa-aaaa.azurewebsites.net/. This is the URL of your live site to which we'll deploy the application.

Learn more at the Web Apps Overview.

Define and test your CD release process

Continuous deployment (CD) means starting an automated release process whenever a new successful build is available. Your CD release process picks up the artifacts published by your CI build and then deploys them to your Azure web site.

  1. Do one of the following:

    • If you've just completed a CI build (see above) then, in the build's Summary tab under Deployments, choose Create release followed by Yes. This starts a new release definition that's automatically linked to the build definition.

    • Open the Releases tab of the Build & Release hub, open the + drop-down in the list of release definitions, and choose Create release definition.

  2. Select the Azure App Service Deployment template and choose Next.

  3. In Source... make sure your CI build definition for the Web deploy package is selected as the artifact source.

  4. Select the Continuous deployment check box, and then choose Create.

  5. Select the Deploy Azure App Service task and configure it as follows:

    Deploy: Azure App Service Deploy
    Deploy: Azure App Service Deploy

    Deploy the app to Azure App Services

    • Azure Subscription: Select a connection from the list under Available Azure Service Connections. If no connections appear, click Manage, then select New Service Endpoint > Azure Resource Manager and follow the prompts. Then return to your release definition, refresh the AzureRM Subscription list, and select the connection you just created.
    • App Service Name: the name of the web app (the part of the URL without .azurewebsites.net)
    • Deploy to Slot: make sure this is cleared (the default)
    • Virtual Application : leave blank
    • Web Deploy Package: $(System.DefaultWorkingDirectory)\**\*.zip (the default)
    • Advanced: Take App Offline: If you run into locked .DLL problems when you test the release, as explained below, try selecting this check box.
  6. Edit the name of the release definition, choose Save, and choose OK. Note that the default environment is named Environment1, which you can edit by clicking directly on the name.

You're now ready to create a release, which means to start the process of running the release definition with the artifacts produced by a specific build. This will result in deploying the build to Azure:

  1. Click + Release and select Create Release.

  2. Select the build you just completed in the highlighted drop-down list and click Create.

  3. Click the release link in the popup message. For example: "Release Release-1 has been created".

  4. Click the Logs tab to watch the release console output.

  5. After the release is complete, navigate to your site running in Azure using the Web App URL http://{web_app_name}.azurewebsites.net, and verify its contents.

NOTE

If you encounter deployment failures with a message about locked .DLL files, then try selecting Advanced: Take App Offline, as mentioned above.

Next steps

Deploy multiple apps in the same release

If your CI build process builds multiple apps, you can deploy them in the same release. To do this, configure a separate instance of the Azure App Service Deploy task for each app. In each instance of the task:

  • Specify a unique value for App Service Name

  • Specify the Web Deploy Package with a reference to a specific app. For example, replace the default value with a more specific value such as $(build.stagingDirectory)\**\WebApplication1.zip

Configure the environment

If you deploy releases to multiple environments, you can substitute configuration settings in Web.config and other configuration files of your website using these steps:

  1. Define environment-specific configuration settings in the Variables tab of an environment in a release definition; for example, connectionString = <value>.

  2. In the Azure App Service Deploy task, select the check box for XML variable substitution under File Transforms and Variable Substitution Options.

    If you prefer to manage environment configuration settings in your own database or Azure keyvault, add a task to the environment to read and emit those values using ##vso[task.setvariable variable=connectionString;issecret=true]<value>.

    The option to select XML variable substitution is only present in version 3.\* and above of the task. It is not yet available in TFS.

Swap deployment slots

If you want to deploy to a staging slot in an Azure Web Apps, and then swap the staging and production slots, perform these steps.

  1. Ensure that your Azure web app has a standard or premium app service plan. This is required to configure deployment slots.

    Specifying the service plan for an Azure web app

  2. Configure a Staging slot in the Azure web app.

    Configuring a staging slot in an Azure web ap

    You do not need to configure a Production slot because it is implicitly present in all Azure web apps.

    For more information on configuring deployment slots, see Set up staging environments for web apps in Azure App Service on the Azure website.

  3. Configure the tasks in the environment of the release definition as follows:

    Azure App Service Deploy
    Deploy: Azure App Service Deploy

    Deploy the app to Azure App Services.

    • Azure Subscription: Select your Azure subscription
    • App Service name: Select your App Service.
    • Deploy to slot: Checked.
    • Slot: Staging
    Azure App Service Manage
    Deploy: Azure App Service Manage

    Swap slots.

    • Azure Subscription: Select your Azure subscription
    • Action: Swap slots
    • App Service name: Select your App Service.
    • Resource group: Select the resource group to which your App Service belongs.
    • Source slot: Staging

Q&A

I use Team Foundation Server on-premises and I don't see some of these features. Why not?

Some of these features are available only on Visual Studio Team Services and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.