Deploying ASP .NET Core 3.1 to Azure App Service
Tags: dotnet, csharp, webdev
Published: 2020-01-27 15:04:49

---
title: Deploying ASP .NET Core 3.1 to Azure App Service
published: true
date: 2020-01-27 15:00:00 UTC
tags: dotnet, csharp, webdev 
canonical_url: https://wakeupandcode.com/deploying-asp-net-core-3-1-to-azure-app-service/
---

![](https://wakeupandcode.com/wp-content/uploads/2020/01/aspnetcore-az-banner.png)

This is the fourth of a new [series of posts](https://wakeupandcode.com/aspnetcore/#aspnetcore2020) on ASP .NET Core 3.1 for 2020. In this series, we’ll cover 26 topics over a span of 26 weeks from January through June 2020, titled  **ASP .NET Core A-Z!**  To differentiate from the [2019 series](https://wakeupandcode.com/aspnetcore/#aspnetcore2019), the 2020 series will mostly focus on a growing single codebase ([NetLearner!](https://wakeupandcode.com/netlearner-on-asp-net-core-3-1/)) instead of new unrelated code snippets week.

Previous post:

- [Cookies and Consent in ASP .NET Core 3.1](https://wakeupandcode.com/cookies-and-consent-in-asp-net-core-3-1/)

**NetLearner on GitHub** :

- Repository: [https://github.com/shahedc/NetLearnerApp](https://github.com/shahedc/NetLearnerApp)
- v0.4-alpha release: [https://github.com/shahedc/NetLearnerApp/releases/tag/v0.4-alpha](https://github.com/shahedc/NetLearnerApp/releases/tag/v0.4-alpha)

# In this Article:

- [D is for Deploying to Azure App Service](#D)
- [Right-Click Publish](#rightclick) 
- [Web Apps in the Azure Portal](#portal) 
- [Runtime Options](#runtime) 
- [Deployment Center](#deployment)
- [GitHub Repos](#github)
- [CLI Commands](#cli)
- [Azure DevOps and YAML](#yaml)
- [References](#refs)

# D is for Deploying to Azure App Service

In this article, we’ll explore several options for deploying an ASP .NET Core web app to Azure App Service in the cloud. From the infamous Right-Click-Publish to fully automated CI/CD, you’ll learn about the latest Deployment Center option in the Azure Portal for App Service for web apps.

**NOTE** : If you’re looking for information on deploying to Docker or Kubernetes, please check out the following docs instead:

- Host and deploy ASP.NET Core: [https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy)
- Deploy to Azure Kubernetes Service: [https://docs.microsoft.com/en-us/azure/devops-project/azure-devops-project-aks](https://docs.microsoft.com/en-us/azure/devops-project/azure-devops-project-aks)
- Host ASP.NET Core in Docker containers: [https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker)
- Dockerize a .NET Core application: [https://docs.docker.com/engine/examples/dotnetcore/](https://docs.docker.com/engine/examples/dotnetcore/)

# Right-Click Publish (aka Friends Don’t Let Friends Right-Click Publish)

If you’ve made it this far, you may be thinking one of the following:  
a. “Hey, this is how I deploy my web apps right now!”  
or  
b. “Hey wait a minute, I’ve heard that you should never do this!”

Well, there is a time and place for right-click publish. There have been many debates on this, so I won’t go into the details, but here are some resources for you to see what others are saying:

- [**MSDN**]  **_When should you right click_ publish** : [https://blogs.msdn.microsoft.com/webdev/2018/11/09/when-should-you-right-click-publish/](https://blogs.msdn.microsoft.com/webdev/2018/11/09/when-should-you-right-click-publish/)
- _ **Friends don’t let friends right-click publish**  _[by  **Damian Brady**]: [https://damianbrady.com.au/2018/02/01/friends-dont-let-friends-right-click-publish/](https://damianbrady.com.au/2018/02/01/friends-dont-let-friends-right-click-publish/)
- _ **In the wild** _ [by  **Geoffrey Huntley**]: [https://rightclickpublish.com/](https://rightclickpublish.com/)

So, what’s a web developer to do? To quote from the aforementioned MSDN article, _“Continuing with the theme of prototyping and experimenting, right click publish is the perfect way for existing Visual Studio customers to evaluate Azure App Service (PAAS). By following the right click publish flow you get the opportunity to provision new instances in Azure and publish your application to them without leaving Visual Studio:”_

In other words, you can use this approach for a quick test or demo, as shown in the screenshots below for Visual Studio.

1. Right-click your ASP .NET Core web app project in Solution Explorer and select Publish.
2. Click the Start button on the screen that appears and follow the onscreen instructions.
3. Ensure that you’re logged in to the correct Azure subscription account you want to publish to.

![Right-click, Publish from Solution Explorer](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-vs2019-publish-1024x426.png)<figcaption>Right-click, Publish from Solution Explorer</figcaption>

![Pick a Publish Target](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-vs2019-publish-target-1024x768.png)<figcaption>Pick a Publish Target</figcaption>

# Web Apps in the Azure Portal

In the screenshot above, you may notice an option to “Import Profile” using the button on the lower left. This allows you to import a Web App profile file that was generated by exporting it from an _existing _Azure Web App. To grab this profile file, simply navigate to your existing Web App in the Azure Portal and click on “Get publish profile” in the top toolbar of your Web App, shown below:

![Get Publish Profile](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-portal-profile-1024x484.png)<figcaption>Get Publish Profile</figcaption>

If you want to create a new Web App in Azure starting with the Azure Portal, follow the instructions below:

1. Log in to the Azure at [https://portal.azure.com](https://portal.azure.com/)
2. On the top left, click + Create a resource
3. Select “Web App” or search for it if you don’t see it.
4. Enter/select the necessary values:
  - Subscription (select a subscription)
  - Resource Group (create or use existing to group resources logically)
  - Web App name (enter a unique name)
  - Publish (Code or Docker Image) 
  - Runtime stack (.NET Core) 

  - App Service Plan (create or use existing to set location and pricing tier)
  - OS (Windows or Linux)  
  - Region (e.g. East US)
5. Click Next through the screens and then click the Create button to complete the creation of your new Web App.

![Create New Web App](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-webapp-new-1024x611.png)<figcaption>Create New Web App</figcaption>

Now you can deploy to this Web App using any method you choose.

# Runtime Options

If you like to stay ahead of ASP .NET Core releases, you may be using a pre-release version of the runtime. As of this writing, the latest stable version of ASP .NET Core is version 3.1, which is already available on Azure. If you’re looking for future preview releases, Azure App Service also has an option to install an Extension for preview runtimes.

To find the proper runtime:

1. Navigate to your Web App in the Azure Portal.
2. Click on Extensions under Development Tools.
3. Click + Add to add a new extension.
4. Choose an extension to configure required settings.
5. Accept the legal terms and complete the installation.

![Add Extension](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-portal-extensions-1024x384.png)<figcaption>Add Extension</figcaption>

Your options may include both 32-bit (x86) and 64-bit (x64) versions of the ASP .NET Core runtime and any preview versions of future releases. When planning ahead for multiple environments, you also have the option to deploy to Deployments Slots. This feature is available in  **Standard** ,  **Premium**  or  **Isolated**  App Service Plan tiers and will covered in a future blog post in this series.

If you’re interested in Deployment Slots right now, check out the official docs at:

- Set up staging environments for web apps in Azure App Service: [https://docs.microsoft.com/en-us/azure/app-service/deploy-staging-slots](https://docs.microsoft.com/en-us/azure/app-service/deploy-staging-slots) 

# Deployment Center

In the list of features for your Web App, you will find an option to open up the new Deployment Center. Note that this has replaced the old Deployment Options. Let’s go over each of these options:

1. Azure Repos
2. Github
3. Bitbucket
4. Local Git
5. OneDrive
6. Dropbox
7. External
8. FTP

![Deployment Options in Deployment Center](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-portal-center1-1024x552.png)<figcaption>Deployment Options in Deployment Center</figcaption>

![More Deployment Options](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-portal-center2-1024x548.png)<figcaption>More Deployment Options</figcaption>

If you choose  **Azure Repos** , you can set up your web app’s CI (Continuous Integration) system with an Azure Repo, which is part of Microsoft’s Azure DevOps services (formerly known as VSTS, aka Visual Studio Team Services). You will have options for using App Service as a Kudu build server or Azure Pipelines as your CI build system.

![Azure Repos choices: Kudu or Pipelines?](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-portal-repos-1024x645.png)<figcaption> Azure Repos choices: Kudu or Pipelines? </figcaption>

If you choose  **Github ** or ** BitBucket ** or even a  **local Git account** , you’ll have the ability to authorize that account to publish a specific repo, every time a developer pushes their code.

![Authorize Github/Bitbucket](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-portal-github-bitbucket-1024x888.png)<figcaption> Authorize Github/Bitbucket </figcaption>

If you choose  **OneDrive**  or  **DropBox** , you’ll have ability to authorize your App Service to pick up files deployed to a shared folder in either location.

![Authorize OneDrive/DropBox](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-portal-onedrive-dropbox-1024x750.png)<figcaption> Authorize OneDrive/DropBox </figcaption>

You may also select an **External** repo or **FTP** source. To learn more about  **Azure Repos**  and  **Azure Pipelines** , check out the official docs:

- Azure Pipelines: [https://docs.microsoft.com/en-us/azure/devops/pipelines](https://docs.microsoft.com/en-us/azure/devops/pipelines)
- Overview: [https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started](https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started)
- Get Started: [https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started-yaml](https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started-yaml)
- Via Portal: [https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started-azure-devops-project](https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started-azure-devops-project)

# GitHub Repos (includes FREE option!)

If you’ve been using GitHub for public open-source projects or private projects on paid accounts, now is a great to time to create private repositories for free! In 2019, GitHub started offering free unlimited private repos, limited to 3 collaborators. This new free option comes with issue/bug tracking and project management as well.

For more information on GitHub pricing, check out their official pricing page:

- GitHub Pricing: [https://github.com/pricing](https://github.com/pricing)

![GitHub pricing: Free vs Pro, Team and Enterprise](https://wakeupandcode.com/wp-content/uploads/2020/01/deploy-github-pricing-1024x486.png)<figcaption> GitHub pricing: Free vs Pro, Team and Enterprise </figcaption>

Now you can easily set up your starter projects in a private GitHub repository and take advantage of the aforementioned CI/CD setup without having to choose between paying a GitHub fee or making all your repos public.

# CLI Commands

If you wish to publish to Azure App service using CLI (Command Line Interface) Commands, you may use the following commands, where you can choose a name for your Web App, Resource Group, App Sevice Plan, etc. Single-letter flags are usually preceded by a single hyphen, while flags spelled out with completed words are usually preceded by two hyphens.

First, install the Azure CLI in case you don’t have it already:

- Install the Azure CLI: [https://docs.microsoft.com/en-us/cli/azure/install-azure-cli](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)

Authenticate yourself:

```
> **az**  **login**
```

Create a new resource group:

```
> **az**  **group** create -l <LOCATION> -n <RSG>> **az**  **group** create --location <LOCATION> --name <RSG>
```

Create a new App Service Plan, where <SKUCODE> sku may be F1 or FREE, etc

```
> **az**  **appservice**  **plan** create -g <RSG> -n <ASP> --sku <SKUCODE> > **az**  **appservice**  **plan** create --resource-group <RSG> --name <ASP> --sku <SKUCODE>
```

From the [documentation](https://docs.microsoft.com/en-us/cli/azure/appservice/plan), the SKU Codes include: F1(Free), D1(Shared), B1(Basic Small), B2(Basic Medium), B3(Basic Large), S1(Standard Small), P1V2(Premium V2 Small), PC2 (Premium Container Small), PC3 (Premium Container Medium), PC4 (Premium Container Large), I1 (Isolated Small), I2 (Isolated Medium), I3 (Isolated Large).

Create a new Web App within a Resource Group, attached to an App Service Plan:

```
> **az**  **webapp** create -g <RSG> -p <ASP> -n <APP> > **az**  **webapp** create --resource-group <RSG> --plan <ASP> --name <APP>
```

The above command should create a web app available at the following URL:

- http://<APP>.azurewebsites.net

To push your commits to a Git Repo and configure for App Service Deployment, use the following CLI commands:

Create a new Git repo or reinitialize an existing one:

```
> **git**  **init**
```

Add existing files to the index:

```
> **git**  **add**.
```

Commit your changes with a commit message:

```
> **git**  **commit** -m "<COMMIT MESSAGE>“
```

Set your FTP credentials and Git deployment credentials for your Web App:

```
> **az**  **webapp**  **deployment**  **user**  **set** --user-name <USER>
```

Configure an endpoint and add it as a git remote.

```
> **az**  **webapp**  **deployment**  **source**  **config-local-git** -g <RSG> -n <APP> --out tsv  > **az**  **webapp**  **deployment**  **source**  **config-local-git** --resource-group <RSG> --name <APP> --out tsv

> **git remote add azure** <GIT URL>
```

The value for GIT URL is the value of the Git remote, e.g.

- https://<USER>@<APP>.scm.azurewebsites.net/<APP>.git

Finally, push to the Azure remote to deploy your Web App:

```
> **git push azure master**
```

For more information on CLI Commands for Git and Azure App Service, check out the official docs:

- Sign in with Azure CLI: [https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli ](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli)
- az appservice plan: [https://docs.microsoft.com/en-us/cli/azure/appservice/plan](https://docs.microsoft.com/en-us/cli/azure/appservice/plan)
- Deploy from local Git repo: [https://docs.microsoft.com/en-us/azure/app-service/deploy-local-git](https://docs.microsoft.com/en-us/azure/app-service/deploy-local-git)
- az webapp deployment user: [https://docs.microsoft.com/en-us/cli/azure/webapp/deployment/user](https://docs.microsoft.com/en-us/cli/azure/webapp/deployment/user)
- Create an app with deployment from GitHub: [https://docs.microsoft.com/en-us/azure/app-service/scripts/cli-deploy-github](https://docs.microsoft.com/en-us/azure/app-service/scripts/cli-deploy-github)
- az webapp deployment source: [https://docs.microsoft.com/en-us/cli/azure/webapp/deployment/source?view=azure-cli-latest](https://docs.microsoft.com/en-us/cli/azure/webapp/deployment/source?view=azure-cli-latest)

# Azure DevOps and YAML

_Wait, what about Azure DevOps and YAML and Pipelines?_

Since this is an A-Z series, you will have to wait for “Y is for YAML” to get more detailed information on constructing your build pipeline using YAML in Azure DevOps. If you can’t wait that long, feel free to check out the following .yml sample I uploaded for use with an ASP .NET Core 3.1:

- YAML for Azure DevOps: [https://github.com/shahedc/YamlForAzureDevOps](https://github.com/shahedc/YamlForAzureDevOps) 

If you’re reading this after June 2020, simply jump right to the “Y is for YAML” post in the [2020 A-Z series](https://wakeupandcode.com/aspnetcore/#aspnetcore2020).

**BONUS** : for Azure SQL Database Deployment, watch the following video on MSDN Channel 9:

- SQL DB Deployment: [https://channel9.msdn.com/Shows/Data-Exposed/Deployment-options-for-Azure-SQL-Database](https://channel9.msdn.com/Shows/Data-Exposed/Deployment-options-for-Azure-SQL-Database) 

# References

- Verify ASP.NET Core on App Service: [https://aspnetcoreon.azurewebsites.net/](https://aspnetcoreon.azurewebsites.net/)
- Deploy a web app to App Services – Azure Pipelines:  [https://docs.microsoft.com/en-us/azure/devops/pipelines/apps/cd/deploy-webdeploy-webapps?view=azure-devops](https://docs.microsoft.com/en-us/azure/devops/pipelines/apps/cd/deploy-webdeploy-webapps?view=azure-devops) 
- Continuous deployment – Azure App Service:  [https://docs.microsoft.com/en-us/azure/devops/pipelines/apps/cd/deploy-webdeploy-webapps?view=azure-devops](https://docs.microsoft.com/en-us/azure/devops/pipelines/apps/cd/deploy-webdeploy-webapps?view=azure-devops) 
- CI/CD for Azure Web Apps: [https://azure.microsoft.com/en-us/solutions/architecture/azure-devops-continuous-integration-and-continuous-deployment-for-azure-web-apps/](https://azure.microsoft.com/en-us/solutions/architecture/azure-devops-continuous-integration-and-continuous-deployment-for-azure-web-apps/)
- Azure Pipelines Overview:  [https://docs.microsoft.com/en-us/azure/devops/pipelines/?view=azure-devops](https://docs.microsoft.com/en-us/azure/devops/pipelines/?view=azure-devops) 
- Get started with Azure Pipelines:  [https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started/index?view=azure-devops](https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started/index?view=azure-devops) 
- Continuous deployment: [https://docs.microsoft.com/en-us/azure/app-service/deploy-continuous-deployment](https://docs.microsoft.com/en-us/azure/app-service/deploy-continuous-deployment)