将 ASP.NET Core 5 应用程序部署到现有的 Azure 应用程序服务? [英] Deploy ASP.NET Core 5 app to existing Azure App Service?

查看:39
本文介绍了将 ASP.NET Core 5 应用程序部署到现有的 Azure 应用程序服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 ASP.NET Core 3.x 上运行的现有 Azure 应用服务.我已将应用程序升级到今天发布的 ASP.NET 核心 5.这在我的本地 IIS Express 服务器上运行良好.但是,当我使用 Visual Studio 2019 将应用程序发布到应用服务时,收到以下错误:

<块引用>

HTTP 错误 500.31 - ANCM 无法找到本机依赖项

此问题的常见解决方案:

未找到指定版本的 Microsoft.NetCore.App 或 Microsoft.AspNetCore.App.

通过启用详细错误,我获得以下附加信息:

找不到任何兼容的框架版本未找到框架Microsoft.AspNetCore.App",版本5.0.0".发现了以下框架:2.1.20 在 [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App]2.1.22 在 [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App]2.2.11 在 [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App]2.2.14 在 [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App]3.0.3 在 [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App]3.1.6 在 [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App]3.1.8 在 [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App]您可以通过安装指定的框架和/或 SDK 来解决问题.可以在以下位置找到指定的框架:https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=5.0.0&arch=x86&rid=win10-x86

我知道ASP.NET Core 5 将立即可用于 Azure 应用服务.我错过了一步吗?如何将 ASP.NET Core 5 Web 应用程序发布到 Azure 应用服务?或者我还需要等到 .NET 5 运行时在 Azure 上可用吗?

解决方案

发行说明 引用,但为了利用新的应用服务抢先体验功能(公告),您需要显式配置您的应用服务以使用 .NET 5 堆栈.

为 .NET 5 配置现有应用服务

要通过现有应用服务的 Azure 门户执行此操作,请完成以下步骤:

  1. 转到要升级的应用服务
  2. 点击左侧导航中的配置
  3. 点击页面级导航中的常规设置
  4. Stack Settings 下,选择 .NET
  5. 框架版本下,选择.NET 5

<块引用>

注意:从技术上讲,一旦执行此操作,您将安装 .NET 5 运行时并可以切换回例如.NET Core 运行时堆栈.但是,这样做会阻止您提前访问 .NET 的后续更新,因此我不建议这样做.

为 .NET 5 配置应用服务

当通过 Azure 门户配置新的应用服务时,这种应用服务早期访问的选择更加明确.在这种情况下,在创建应用服务时,系统会提示您选择运行时堆栈,在该堆栈下,.NET 5 被明确标记为.NET 5(抢先体验).

<块引用>

注意:如果您已将另一个应用服务配置为在同一应用服务计划中使用应用服务抢先体验,则 .NET 5 运行时将已安装并可用.这是因为 .NET 运行时在同一应用服务计划中的应用服务之间共享.

Visual Studio 发布警告

即使使用抢先体验功能,假设您启用了版本兼容性检查,您在从 Visual Studio 2019 16.8 发布时可能仍会收到以下警告:

<块引用>

您的应用程序需要 .NET Core 5.0.0 运行时,但 Microsoft Azure 应用服务仅支持以下版本:2.1.20、2.1.22、2.2.11、2.2.14、3.0.3、3.1.6、和 3.1.8.

尽管如此,一旦您发布所有内容,即使您使用的是依赖框架部署模式.

应用洞察

警告:应用服务抢先体验功能不支持 Application Insights 集成.我创建了一个问题请求有关 Application Insights 兼容性的状态更新2020 年 11 月,但我不希望很快得到解决:后续主题 没有解决就关闭了.

如果您仍然依赖 Application Insights 的 Azure 集成,我建议您迁移到 SDK 实现.

<块引用>

注意:在 ASP.NET Core 中配置 Application Insights SDK 比在早期版本的 .NET Framework 中配置要简单得多,并且需要更少的样板代码.

替代方案

作为替代方案,您可以选择在发布配置文件 (*.pubxml) 中使用 Self Contained 部署模式进行部署.这是 .NET 5 之前 Azure 应用服务上的 .NET Core 新版本所需的方法,并且今天继续得到支持.

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)dotnetsharedMicrosoft.AspNetCore.App] 
2.1.22 at [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App] 
2.2.11 at [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App] 
2.2.14 at [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App] 
3.0.3 at [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App] 
3.1.6 at [D:Program Files (x86)dotnetsharedMicrosoft.AspNetCore.App] 
3.1.8 at [D:Program Files (x86)dotnetsharedMicrosoft.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?

解决方案

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.

这篇关于将 ASP.NET Core 5 应用程序部署到现有的 Azure 应用程序服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆