构建成功但是发布失败-Microsoft.AspNetCore.All这个版本只兼容netcoreapp2.2目标框架

Build is success but publish fails - This version of Microsoft.AspNetCore.All is only compatible with the netcoreapp2.2 target framework

我有一个具有以下属性的 Web API 项目

项目 .csproj 显然具有以下设置

<PropertyGroup>
   <TargetFramework>netcoreapp2.2</TargetFramework>
 </PropertyGroup>

在 Visual Studio 中构建 success,但是当我尝试 publish 项目时,出现以下错误

This version of Microsoft.AspNetCore.All is only compatible with the netcoreapp2.2 target framework. Please target netcoreapp2.2 or choose a version of Microsoft.AspNetCore.All compatible with netcoreapp2.1.

我正在使用 Visual Studio 菜单选项进行发布。 我正在发布到 Azure app service 。发布到 File System 没有显示任何错误。

我有如下 nuget

可能是什么原因?

不知道它是否与您相关,但我在文件夹发布目标位置设置中找到了这个:

我刚刚找到了一个奇怪的解决方案!

我创建了新的 publish 配置文件,它非常有效!似乎在将项目 属性 从 .Net Core 2.1 更改为 .Net Core 2.2 之后,我们总是需要创建一个新的配置文件!