ASP.NET Core 3.1 API 引用 .Net Standard class 库 - 在 Azure DevOps 中构建失败

ASP.NET Core 3.1 API referring to a .Net Standard class library - build failed in Azure DevOps

我正在开发一个 ASP.NET Core 3.1 API,它指的是一个 .NET Standard 2.1 class 库。当我使用 Visual Studio 从我的本地计算机 运行 API(没有任何错误和警告)时,它按预期工作正常。

但是当我使用 Azure DevOps 进行部署时,构建失败并显示以下消息:

Build Steps 2 error(s), 0 warning(s)
The nuget command failed with exit code(1) and error(NU1201: Project ISOXMLValidationLibrary is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project ISOXMLValidationLibrary supports: netstandard2.1 (.NETStandard,Version=v2.1)
NU1201: Project ISOXMLValidationLibrary is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project ISOXMLValidationLibrary supports: netstandard2.1 (.NETStandard,Version=v2.1)

Errors in
D:\a\s\ISOXMLValidationApi\ISOXMLValidationApi\ISOXMLValidationApi.csproj NU1201: Project ISOXMLValidationLibrary is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project ISOXMLValidationLibrary supports: netstandard2.1 (.NETStandard,Version=v2.1) Errors in D:\a\s\ISOXMLValidationApi\ISOXMLValidationApiTest\ISOXMLValidationApiTest.csproj NU1201: Project ISOXMLValidationLibrary is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project ISOXMLValidationLibrary supports: netstandard2.1 (.NETStandard,Version=v2.1))

包无法恢复

请告诉我如何解决这个问题?

我通过将 class 库的目标框架从 .net standard 2.1 更改为 .net standard 2.0 解决了这个问题。

在我的例子中,问题是由于旧的 Nuget 版本引起的。尝试将 Nuget 版本更改为更新版本(最好是最新版本)。 您可以在 https://dist.nuget.org/tools.json

找到 TFS 或 Azure DevOps 服务器中可用的版本列表

就我而言,在我的机器上构建一个旧项目没问题,但失败了

Package IdentityModel 4.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1).

关于构建代理。

在(与项目一样旧)构建定义中添加“使用 NuGet 5.8.x”步骤解决了问题。