简体   繁体   English

NuGet 恢复失败 - .NET 7.0 与 .NET 标准 2.0 的兼容性

[英]NuGet Restore Fails - .NET 7.0 compatibility with .NET Standard 2.0

I have a solution with a .NET 7.0 ASP.NET project which has a project reference on a .NET Standard 2.0 library in the same solution.我有一个 .NET 7.0 ASP.NET 项目的解决方案,该项目在同一解决方案中的 .NET 标准 2.0 库中有一个项目参考。 All builds and executes fine on my machine.在我的机器上所有构建和执行都很好。

I have a Pipeline in Azure DevOps that builds the projects and aims to deploy the ASP.NET project to a server.我在 Azure DevOps 中有一个管道,用于构建项目并旨在将 ASP.NET 项目部署到服务器。 Before building, it runs the task NuGetCommand@2 to execute a NuGet Restore against **/*.sln .在构建之前,它运行任务NuGetCommand@2以针对**/*.sln执行 NuGet 恢复。 This is being run on the windows-2022 Azure VM Image.这是在windows-2022 Azure VM 映像上运行的。

The restore bombs because of errors like these:由于以下错误,恢复炸弹:

Package Microsoft.OpenApi 1.4.3 is not compatible with net70 (.NETFramework,Version=v7.0). Package Microsoft.OpenApi 1.4.3 supports: netstandard2.0 (.NETStandard,Version=v2.0)
Errors in D:\a\1\s\MyApp.csproj
    Project MyLibrary is not compatible with net70 (.NETFramework,Version=v7.0). Project MyLibrary supports: netstandard2.0 (.NETStandard,Version=v2.0)

This reads to me like it's saying you can't consume .NET Standard 2.0 libraries in a .NET 7.0 project, but the compatibility docs seem to claim otherwise.这对我来说就像是在说您不能在 .NET 7.0 项目中使用 .NET 标准 2.0 库,但兼容性文档似乎另有说明。 What's going on here?这里发生了什么?

update on 12/3 12/3更新

During the investigations and referencing on this issue, I found this ticketGithub_Nuget_Tool_Cache_issue#16800 , more developers are confused with this by-design behavior.在调查和参考这个问题的过程中,我发现了这张票Github_Nuget_Tool_Cache_issue#16800 ,更多的开发人员对这种设计行为感到困惑。

So far, the only workaround seems to be the extra installation of 6.4.x .到目前为止,唯一的解决方法似乎是额外安装6.4.x

You could also raise a feature request ticket to raise more concern for future update on this behavior.您还可以提出功能请求票以引起更多关注,以便将来对此行为进行更新。

================================================================ ================================================ ==============

Original post on 12/1 12/1 的原始帖子

I installed the latest nuget version of 6.4.0.123 with nuget tool installer task to ensure the compatibility for Microsoft.OpenApi 1.4.3 with.net7.0.我用nuget tool installer 任务安装了最新的nuget版本的6.4.0.123来确保Microsoft.OpenApi 1.4.3与.net7.0的兼容性。

====================================================== ================================================ ====

updated on 12/2 12月2日更新

From the source page of Microsoft.OpenAPI.1.4.3 , this version is designed to be compatible with DotNet 7.0.Microsoft.OpenAPI.1.4.3的源码页面来看,这个版本是为了兼容 DotNet 7.0 而设计的。

During the investigations, I look into the debug logs, I found that the nuget restore task is using the cache version with 4.x in window-2022.在调查过程中,我查看了调试日志,发现 nuget 还原任务在 window-2022 中使用4.x的缓存版本。 And I suppose that this version is surely not compatible with do.net 70.我想这个版本肯定与 do.net 70 不兼容。 在此处输入图像描述

After installing the later nuget version to 6.4.x , everything is compatible.将后面的nuget版本安装到6.4.x后,一切都兼容了。 在此处输入图像描述

So I suppose the nuget version could be the key to result in the different behavior.所以我想 nuget 版本可能是导致不同行为的关键。 (even maybe by design that the Nuget 4.1 could not recognize the compatibility between Microsoft.OpenAPI1.4.3 and Do.net 7.0 ) (甚至可能是设计使Nuget 4.1无法识别Microsoft.OpenAPI1.4.3Do.net 7.0之间的兼容性)

Reference参考

NuGet 4.9 Release Notes NuGet 4.9 发行说明

NuGet 5.11 Release Notes NuGet 5.11 发行说明

NuGet 6.4 Release Notes NuGet 6.4 发行说明

Based on @Ceeno's answer, but including for those running YAML pipelines.基于@Ceeno 的回答,但包括那些运行 YAML 管道的人。

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/nuget-tool-installer-v1?view=azure-pipelines https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/nuget-tool-installer-v1?view=azure-pipelines

I just opted to get the latest version.我只是选择获取最新版本。

- task: NuGetToolInstaller@1
  displayName: 'Update NuGet'
  inputs:
    checkLatest: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM