Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy ASP.NET Core 5 app to existing Azure App Service?

I have an existing Azure App Service running on ASP.NET Core 3.x. I have upgraded the application to today’s release of ASP.NET Core 5. This works fine on my local IIS Express server. When I publish to the application to the App Service using Visual Studio 2019, however, I receive the following error:

HTTP Error 500.31 - ANCM Failed to Find Native Dependencies

Common solutions to this issue:

The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.

With detailed errors enabled, I get the following additional information:

It was not possible to find any compatible framework version 
The framework 'Microsoft.AspNetCore.App', version '5.0.0' was not found.

The following frameworks were found: 
2.1.20 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 
2.1.22 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 
2.2.11 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 
2.2.14 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 
3.0.3 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 
3.1.6 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 
3.1.8 at [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] 

You can resolve the problem by installing the specified framework and/or SDK. 

The specified framework can be found at:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=5.0.0&arch=x86&rid=win10-x86

I had understood that ASP.NET Core 5 would be immediately available on Azure App Services. Am I missing a step? How can I publish an ASP.NET Core 5 web application to an Azure App Service? Or do I still need to wait until the .NET 5 runtime is available on Azure?

like image 269
Jeremy Caney Avatar asked Nov 10 '20 22:11

Jeremy Caney


People also ask

Does Azure support .NET Core 5?

NET Core 3.1 and . NET 5 Azure Functions are. As of March 2021, Microsoft announced that Azure Functions are supported running on . NET 5.


Video Answer


1 Answers

It's not entirely clear from the release notes referenced, but in order to take advantage of the new App Service Early Access feature (announcement), you need to explicitly configure your App Service to use the .NET 5 stack.

Configuring an existing App Service for .NET 5

To do this via the Azure Portal for an existing App Service, complete the following steps:

  1. Go to the App Service you want to upgrade
  2. Click on Configuration on the left-hand navigation
  3. Click on General Settings in the page-level navigation
  4. Under Stack Settings, select .NET
  5. Under Framework Version, select .NET 5

Note: Technically, once you do this, you'll have the .NET 5 runtime installed and could switch back to e.g. the .NET Core runtime stack. Doing so, however, would prevent you from gaining early access to subsequent updates to .NET, so I wouldn't recommend it.

Configuring a new App Service for .NET 5

This opt-in for the App Service Early Access is far more explicit when configuring a new App Service via the Azure Portal. In that case, when creating an App Service, you'll be prompted to select the Runtime stack, under which .NET 5 is explicitly labeled as .NET 5 (Early Access).

Note: If you already have another App Service configured to use App Service Early Access on the same App Service Plan, then the .NET 5 runtime will already be installed and available. This is because .NET runtimes are shared between App Services on the same App Service Plan.

Visual Studio publishing warnings

Even with the Early Access feature, you may still receive the following warning when publishing from Visual Studio 2019 16.8, assuming you have version compatibility checks enabled:

Your application requires the .NET Core 5.0.0 runtime, but Microsoft Azure App Service only supports the following versions: 2.1.20, 2.1.22, 2.2.11, 2.2.14, 3.0.3, 3.1.6, and 3.1.8.

Despite that, once you publish everything should work, even if you're using the Framework-dependent deployment mode.

Application Insights

As a word of warning: The current implementation of the App Services Early Access feature doesn't yet support Application Insights integration. I created an issue requesting status updates regarding Application Insights compatibility back in November 2020, but I'm not expecting a resolution anytime soon: a follow-up thread was closed without resolution.

If you're still relying on the Azure integration of Application Insights, I recommend that you migrate to the SDK implementation.

Note: Configuring the Application Insights SDK in ASP.NET Core is dramatically simpler than it was in earlier versions of .NET Framework, and requires far less boilerplate code.

Alternatives

As an alternative, you can instead choose to deploy using the Self Contained deployment mode in your publishing profile (*.pubxml). This was the approach required for new releases of .NET Core on Azure App Services prior to .NET 5, and it continues to be supported today.

like image 78
Jeremy Caney Avatar answered Sep 28 '22 13:09

Jeremy Caney