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

查看:33
本文介绍了将 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. 堆栈设置下,选择.NET
  5. 框架版本下,选择.NET 5

<块引用>

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

为 .NET 5 配置应用服务

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

<块引用>

注意:如果您已将另一个应用服务配置为在同一应用服务计划上使用应用服务早期访问,则 .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.

尽管如此,一旦你发布了一切都应该可以工作,即使你使用的是Framework-dependent部署模式.

应用洞察

作为警告:App Services Early Access 功能不支持 Application Insights 集成.我创建了一个请求有关 Application Insights 兼容性的状态更新的问题2020 年 11 月,但我预计不会很快有解决方案:后续线程 没有解决就关闭了.

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

<块引用>

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

替代品

作为替代方案,您可以选择使用发布配置文件 (*.pubxml) 中的自包含 部署模式进行部署.这是 .NET 5 之前的 Azure App Services 新版本 .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天全站免登陆