Exercise - Publish to Azure App Service (optional)

Completed

Many integrated development environments and other tools can publish an ASP.NET Core app to various hosting environments. Behind the scenes, these tools are running the dotnet publish command with various options.

Your manager is evaluating Azure as an option for hosting your app, and they asked you to publish the app as a proof-of-concept. You need to publish the app on Azure. You've selected Azure App Service as the hosting environment because it's easy to use and supports ASP.NET Core apps.

In this exercise, you publish an ASP.NET Core app as a framework-dependent deployment for Azure.

Note

This exercise is optional. If you don't have an Azure subscription, you can get a free account or skip this exercise.

Create an Azure App Service web app

In Azure App Service, a web app can be thought of as a single-application web server. You need to create an Azure App Service web app in which to deploy your ASP.NET Core app. Make sure you have the Azure Tools extension for Visual Studio Code installed.

  1. In Visual Studio Code, press Ctrl+Shift+A to open the Azure Tools extension.

  2. Sign in to your Azure subscription and directory if necessary.

  3. Press Ctrl+Shift+P to open the command palette.

  4. Search for and select Azure App Service: Create New Web App.... Do NOT select the Advanced option.

    A screenshot of the command palette with the Create a New Web App option selected.

  5. Select the subscription you want to use.

  6. Enter a name for the web app. The name must be unique within Azure.

  7. Select the correct .NET runtime stack.

    Tip

    This usually corresponds to the version of the .NET SDK you're using. For example, if you're using .NET 8.0, you should select .NET 8.0. If you're not sure which runtime stack to use, check the <TargetFramework> element in the MyWebApp.csproj file.

  8. Select the Free (F1) pricing tier.

  9. After the extension finishes creating the web app, return to the Azure Tools extension. Note that the App Services node under your subscription now contains the new web app.

    A screenshot of the Azure Tools extension listing the Azure App Service web app.

Publish the app to Azure

Now that you've created the Azure App Service web app, you can publish the app to Azure.

  1. Press Ctrl+Shift+P to open the command palette.

  2. Search for and select Azure App Service: Deploy to Web App....

  3. Select the folder that contains your project.

  4. When prompted, select Add Config to add a configuration file for the app.

  5. Select the Azure subscription you used earlier.

  6. Select the web app you created earlier.

  7. When prompted, select Deploy.

    After a few moments, the app is published to Azure. In the Terminal window, you can see the output of the publish-release task. Note that the extension runs the dotnet publish command to create a framework-dependent deployment.

    A screenshot of the terminal output featuring the dotnet publish command.

  8. When prompted, select Browse Website to open the web app in a browser. Alternatively, press Ctrl+Shift+P and search for Azure App Service: Browse Website and follow the prompts.