Running a .NET 6 ASP.NET Application on Azure Cloud Services

I have a project where I need to migrate a large and complicated ASP.NET application running on .NET Framework to .NET 6. This migration is further complicated by the fact that the application is currently running in production using Microsoft Azure’s Cloud Services offering. This is an older form of deployment which predates the newer App Service. Unfortunately, Cloud Services does not ship with native .NET 6 support, at least at the time of writing. 

It would not have helped if the application was migrated to .NET 6, but it could not run in production – thus, figuring out how to get .NET 6 running on Cloud Services was the first step of the project. Luckily, there is this excellent post by Claire Novotny which explains how to do the same thing – except for .NET Core 2 instead of .NET 6 (I know – Microsoft’s naming has been really confusing lately). There are some things that have changed since then, which I will explain below. I will not be explaining the full process which would mostly just be a copy of what Claire has already explained. Refer to her post for that. 

The first change – instead of creating a new ASP.NET Core 2 project, you need to create an ASP.NET Core Web App that uses the .NET 6.0 (Long-term support) Framework. 

Another small change needs to be made to the .csproj file of the web role. The include path refers to the ASP.NET Core 2 bin output directory. This has to be changed to the .NET 6 bin output directory:

<Content Include="..\TheWebsite\bin\$(Configuration)\net6.0\publish\**\*.*" Link="%(RecursiveDir)%(Filename)%(Extension)" />

The rest of the changes are within the Startup.ps1 file. The script looks for the dotnet.exe and if it finds it, it assumes that .NET Core is not installed, and then downloads the installer from Microsoft. I noticed this script kept failing and after some investigation, it appears that the virtual machine image did have the dotnet.exe file, just not .NET 6. It only included .NET Core 3.1 and .NET 5. 

To work-around this for now, I just commented out the if check, and always download the installer file if not in an emulated environment. A better approach I will still implement is to check if the .exe is there, and if it is, check the version is .NET 6. Later virtual machine images will likely include it. 

Next, I changed the .NET Hosting Bundle installer file being downloaded to the .NET 6 version as well as the Visual C++ distributable installer to the one referred to here: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/hosting-bundle 

After making those changes and deploying I was greeted with: 

I also made some changes to the default template, notably calling Environment.ProcessPath which was only introduced in .NET 6. 

You can also download the complete solution from my GitHub account.  

Leave a comment

Your email address will not be published.