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

此生再无相见时 提交于 2021-02-04 13:07:55

问题


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, 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.

Specific error detected by ANCM:

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?


回答1:


It's not entirely clear from the release notes you 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.

Limitations

As a word of warning: The current implementation of the App Services Early Access feature doesn't yet support Application Insights integration. As such, if you're relying on the automatic integration from Azure, instead of custom instrumentation, you may want to wait until the App Service Early Access feature supports Application Insights integration.

Note: I’ve created an issue requesting status updates regarding Application Insights compatibility, but haven’t yet heard back.

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.



来源:https://stackoverflow.com/questions/64777919/deploy-asp-net-core-5-app-to-azure-app-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!