Deploy an ASP.NET Core container to Azure App Service using Visual Studio

This tutorial walks you through using Visual Studio to publish your containerized ASP.NET Core web application to an Azure App Service. Azure App Service is an appropriate service for a single-container web app hosted in Azure.

If you don't have an Azure subscription, create a free account before you begin.

Prerequisites

To complete this tutorial:

Create an ASP.NET Core web app

The following steps guide you through creating a basic ASP.NET Core app that will be used in this tutorial.

  1. From the Visual Studio start window, choose Create a new project.
  2. Choose ASP.NET Core Web App, and choose Next.
  3. Give your new application a name (or take the default) and choose Next.
  4. Choose the .NET version you want to target. If you're not sure, choose the .NET 8.0 version.
  5. Choose whether or not you want SSL support by using the Configure for HTTPS checkbox.
  6. Select the Enable Docker Support checkbox.
  7. Select the container type, and click Create.

Deploy the container to Azure

  1. Right-click your project in Solution Explorer and choose Publish.

  2. On the Publish dialog, choose the Azure target.

    Screenshot of Publish wizard.

  3. On the Specific target tab, choose the appropriate deployment target, such as App Service (Windows) or App Service (Linux), depending on your container type.

    Screenshot of Specific target tab of Publish wizard.

  4. If you are not signed in to the right Azure account with the subscription you want to use, sign in by using the button at the top left of the Publish window.

  5. You can use an existing app service or create a new one by clicking on the Create new Azure App Service link. Find your existing app service in the treeview by expanding its resource group, or change the View setting to Resource type to sort by type.

    Screenshot showing choosing an App Service.

  6. If you create a new one, a resource group and app service will be generated in Azure. You can change the names if desired, as long as they are unique.

    Screenshot showing creating an App Service.

  7. You can accept the default hosting plan or change the hosting plan now, or later in the Azure portal. The default is S1 (small) in one of the supported regions. To create a hosting plan, choose New next to the Hosting Plan dropdown list. The Hosting Plan window appears.

    Screenshot showing hosting plan options.

    You can view the details about these options at Azure App Service plan overview.

  8. Once you're done selecting or creating these resources, choose Finish. Your container is deployed to Azure in the resource group and app service you selected. This process takes a bit of time. When it's completed, the Publish tab shows information about what was published, including the site URL.

    Screenshot of publish tab.

  9. Click on the site link to verify your app works as expected in Azure.

    Screenshot of web application.

  10. The publishing profile is saved with all the details you selected, such as the resource group and app service.

  11. To deploy again with the same publishing profile, use the Publish button, the Publish button on the Web Publish Activity window, or right-click on the project in Solution Explorer and choose the Publish item on the context-menu.

  1. Right-click your project in Solution Explorer and choose Publish.

  2. On the Publish dialog, choose the Azure target.

    Screenshot of Publish wizard.

  3. On the Specific target tab, choose the appropriate deployment target, such as Azure App Service Container. App Service (Linux), or App Service (Windows), depending on your container type. Choose Azure App Service Container if you want to deploy your image to Azure Container Registry.

    Screenshot of Specific target tab of Publish wizard.

  4. If you are not signed in to the right Azure account with the subscription you want to use, sign in by using the button at the top left of the Publish window.

  5. You can use an existing app service or create a new one by clicking on the Create new Azure App Service link. Find your existing app service in the treeview by expanding its resource group, or change the View setting to Resource type to sort by type.

    Screenshot showing choosing an App Service.

    Note

    In Visual Studio 2022 version 17.11, the default authentication method used for publishing to Azure changed from basic authentication to using an access token for authentication. To use basic authentication with Visual Studio 17.11 or later, clear the checkbox Enable secure publishing (not recommended).

  6. If you create a new one, a resource group and app service will be generated in Azure. You can change the names if desired, as long as they are unique.

    Screenshot showing creating an App Service.

  7. You can accept the default hosting plan or change the hosting plan now, or later in the Azure portal. The default is S1 (small) in one of the supported regions. To create a hosting plan, choose New next to the Hosting Plan dropdown list. The Hosting Plan window appears.

    Screenshot showing hosting plan options.

    You can view the details about these options at Azure App Service plan overview.

  8. If you chose the Azure App Service Container option, specify whether to use an existing registry or create a new one. If you create a new one, a screen appears with settings for the new registry. For the description of the options for SKU, see Azure Container Registry service tiers.

    Screenshot showing Azure Container Registry options.

  9. Once you're done selecting or creating these resources, choose Finish. Your container is deployed to Azure in the resource group and app service you selected. This process takes a bit of time. When it's completed, the Publish tab shows information about what was published, including the site URL.

    Screenshot of publish tab.

  10. The publishing profile is saved with all the details you selected, such as the resource group and app service. If you chose Azure App Service Container, you might be asked to enable the Admin user on the Container Registry instance.

  11. Click on the site link to verify your app works as expected in Azure.

    Screenshot of web application.

  12. To deploy again with the same publishing profile, use the Publish button, the Publish button on the Web Publish Activity window, or right-click on the project in Solution Explorer and choose the Publish item on the context-menu.

View container settings

In the Azure portal, you can open your deployed App Service.

You can view settings for your deployed App Service by opening the Container settings menu (when you are using Visual Studio 2019 version 16.4 or later).

Screenshot of Container Settings menu in the Azure portal.

From there, you can view the container information, view or download logs, or set up continuous deployment. See Azure App Service Continuous Deployment CI/CD.

Clean up resources

To remove all Azure resources associated with this tutorial, delete the resource group using the Azure portal. To find the resource group associated with a published web application, choose View > Other Windows > Web Publish Activity, and then choose the gear icon. The Publish tab opens, which contains the resource group.

In the Azure portal, choose Resource groups, select the resource group to open its details page. Verify that this is the correct resource group, then choose Remove resource group, type the name, and choose Delete.