Running .NET 5 on Azure App Services

Tobias Zimmergren
Tobias Zimmergren

I recently had a few discussions about some heavily-loaded Blazor apps I've built. They are all running on .NET Core 3.1, but I am attempting to get them up to .NET 5 (Preview).

In these discussions, it came up that it wasn't at the time of our dialogs, possible to publish to Azure App Services with success. However, it seems that it works now - but again, it is a preview. Expect changes, perhaps even breaking changes, and don't ship to production just yet - at least that's what I'd recommend.

I have successfully upgraded two out of eight personal projects. Still, many dependencies fail in the remaining projects, and until that's a story of success, I'll happily share the process here, simplified with a new Blazor project.

Tag along for:

  • Upgrading our existing projects from .NET Core 3.1 to .NET 5.
  • Set up a brand new project and directly target .NET 5.
  • What about breaking changes?
  • Is it working in the cloud?

Install the .NET 5 SDK for Visual Studio 2019

During the initial draft of this blog post, I am targeting a preview version of .NET 5. As things mature, I will update this post with the released LTS version.

Get the SDK installer from the website:

When I publish this post, the SDK version is "v5.0.100-preview.4"

What to know about .NET 5 versus .NET Core

Something that has changed over the iterations of the preview and that seems to be reliable information finally is the naming of the target framework. Here's a quote from the Microsoft website:

Targeting API versions will be simpler with .NET going forward. We won’t have two families of TFMs, like: netcoreapp3.1 and netstandard2.0. Instead, we’ll have just one, like: net5.0, and net6.0. That’s because there is just one .NET implementation going forward, so there is no longer a need for .NET Standard

What we need to know is:

  • We don't need to use netcoreapp5.0 (as the earlier previews)
  • We don't need to distinguish between netcoreapp and netstandard
  • We specifically target net5.0 for both types of projects. Finally!

Upgrading an existing Web App to .NET 5

Currently, I am hosting all my Azure Web Apps with .NET Core 3.1. I intend to move them all over to .NET 5 in a separate branch to see how it works, so here goes.

For this blog post, I have created a new .NET Core 3.1 Web App that I will upgrade. My actual project contains dependencies that I know does not have any .NET 5 previews yet, unfortunately.

You can, of course, also create a new project and do the below steps to get up and running.

Updates in the .csproj file

To get my existing projects up and running, I will have to switch the target framework and any dependencies to the latest version of .NET 5 that I want to target.

  • TargetFramework: Change to "net5.0"

My simplified .csproj file looks like this. You can set the TargetFramework directly in the file:

<Project Sdk="Microsoft.NET.Sdk">
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
    <None Update="host.json">
    <None Update="local.settings.json">

You can also set the TargetFramework from the Project properties and look at the Target Framework:

Selecting Target Framework as .NET 5.0 for an Azure Function project.

Update dependencies

I have many dependencies on many of my projects. My Azure Web Apps aren't always running only the Web App itself but have dependencies on other projects in the solutions, NuGet packages, and more.

Whether or not you can get all of your codebases up to the current version of .NET 5 is something you'll have to explore for your scenarios.

In one of my projects, it can look like this, where I make sure to update dependencies to the latest versions as well.

Update NuGet dependencies to fit .NET 5

Be aware of breaking changes

I think tests should cover any code flying into a production environment. When you upgrade your projects, you'd see immediately if you have any noticeable breaking changes in your system due to changes in the SDKs.

Integration tests could be a way to ensure that the end-to-end flow works, as well.

An excellent way to stay ahead is to keep an eye on the ASP.NET Announcements GitHub repository. Filter the repository issues like this:

  • Milestone: 5.0
  • Label: "Breaking change"

You can use this URL to go directly to that filter:"Breaking+change"+milestone%3A5.0

Publish and run in Azure

Since the days of .NET 5 are early, and we're still in a preview as of writing this, there will be changes and improvements to this process.

For now, I am using a self-contained deployment that runs in an Azure App Service on Windows. Magically beautiful.

Configure self-contained deployment.

I like the "self-contained" deployment option. It packages your app in a self-contained executable that does not require .NET to be installed on the app service. Instead, the bundle comes with everything it needs to run.

Publish to Azure

I am publishing this from my Visual Studio project because it's a demo. My real projects are all running through GitHub Actions or Azure DevOps.

Right click the project and select Publish from Visual Studio 

Per the usual deployment routine from Visual Studio, select Azure as the target:

Select Azure as the destination for publishing our Web App.

Select Azure App Service (Windows), which is what I'll be doing here:

Select Azure App Service (Windows) as a deployment target from Visual Studio.

Next, next, finish!

Selecing or creating a new App Service Plan in the Publish dialog

Modify the Configuration, which we'll do to modify how we package the solution.

Edit the release configuration in order to configure how the app will run.
Select a self-contained deployment mode, then hit Save.

Next up, Publish to Azure and test out your web app. It should, if all things have gone well, run .NET 5 on your Azure App Service.

The new app is up and hosted in Azure, running .NET 5.

To re-iterate, we have now:

  • Created an Azure App Service (Windows) in Azure.
  • We created a publishing profile from Visual Studio for demo and dev purposes.
  • Modified the configuration and set it to Self-Contained.
  • Published to Azure.
  • We have seen it in action in Azure.

Header photo by Carlos Muza on Unsplash

AzureApp Service.NET

Tobias Zimmergren Twitter

Hi, I'm Tobias! 👋 I write about Microsoft Azure, security, cybersecurity, compliance, cloud architecture, Microsoft 365, and general tech!

Reactions and mentions

Hi, I'm Tobias 👋

Tobias Zimmergren profile picture

Find out more about me.

Recent comments