【问题标题】:VSTS build: Packages failed to restore - Unable to resolve 'NETStandard.Library (>= 1.6.1)' for '.NETStandard,Version=v2.0'VSTS 构建:包无法恢复 - 无法解析 '.NETStandard,Version=v2.0' 的 'NETStandard.Library (>= 1.6.1)'
【发布时间】:2017-08-16 15:13:05
【问题描述】:

我来了

无法为“.NETStandard,Version=v2.0”解析“NETStandard.Library (>= 1.6.1)”。

在我将我的 aspnetcore 应用程序升级到 netcoreapp2.0 并将我的库升级到使用 netstandard2.0 之后,在使用 Hosted2017 构建代理的 VSTS 构建中。

在本地运行良好。

我已编辑我的构建定义以使用 .net 核心构建任务v2.* preview

这是构建日志:

Current agent version: '2.120.2'
Download all required tasks.
Downloading task: DotNetCoreCLI

Starting: Get Sources
Syncing repository: Liero/vyvojari-sk (GitHub)
...details ommited
HEAD is now at e448a25... Upgraded to .NET Core 2.0
Finishing: Get Sources

Starting: Restore
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
Version      : 2.0.5
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
==============================================================================
SYSTEMVSSCONNECTION exists true
Downloading: https://dist.nuget.org/win-x86-commandline/v4.0.0/nuget.exe
Caching tool: NuGet 4.0.0 x64
Using version: 4.0.0
Found tool in cache: NuGet 4.0.0 x64
Saving NuGet.config to a temporary config file.
Can\'t find loc string for key: NGCommon_NoSourcesFoundInConfig
NGCommon_NoSourcesFoundInConfig d:\a\1\Nuget\tempNuGet_734.config
"C:\Program Files\dotnet\dotnet.exe" restore d:\a\1\s\src\CommandStack\CommandStack.csproj --configfile d:\a\1\Nuget\tempNuGet_734.config --verbosity Detailed
  Restoring packages for d:\a\1\s\src\CommandStack\CommandStack.csproj...
C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Unable to resolve 'NETStandard.Library (>= 1.6.1)' for '.NETStandard,Version=v2.0'. [d:\a\1\s\src\CommandStack\CommandStack.csproj]
  Generating MSBuild file d:\a\1\s\src\CommandStack\obj\CommandStack.csproj.nuget.g.props.
  Generating MSBuild file d:\a\1\s\src\CommandStack\obj\CommandStack.csproj.nuget.g.targets.
  Writing lock file to disk. Path: d:\a\1\s\src\CommandStack\obj\project.assets.json
  Restore failed in 115.64 ms for d:\a\1\s\src\CommandStack\CommandStack.csproj.

  Errors in d:\a\1\s\src\CommandStack\CommandStack.csproj
      Unable to resolve 'NETStandard.Library (>= 1.6.1)' for '.NETStandard,Version=v2.0'.

  NuGet Config files used:
      d:\a\1\Nuget\tempNuGet_734.config
Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
Packages failed to restore
******************************************************************************
Finishing: Restore
******************************************************************************

这里是源代码:https://github.com/Liero/vyvojari-sk/tree/e448a25fb8c481704e9102aaaeb8b84b9aee7b02

【问题讨论】:

  • 代理上似乎使用了 1.0.4 SDK,而托管代理可能尚未使用 2.0.0 SDK 进行更新
  • 但是你看到还原任务使用的是v2.0.5
  • 这就是任务。我看到C:\Program Files\dotnet\sdk\1.0.4
  • 我还添加了 .NET Core Tool Installer 任务来安装 v2.0.0 并且输出仍然相同
  • 嗯,当我检查“我在此处选择的源”而不是预选“我的 NuGet.config 中的源”并确保“使用 NuGet.org 中的包”时,它看起来像检查它的工作原理。有人可以验证吗?

标签: .net-core azure-devops azure-pipelines .net-core-2.0 .net-standard-2.0


【解决方案1】:

2017 年 9 月 18 日更新

不再需要第 2 步。我把它留在了解决方案中,因为它仍然可以帮助一些人。谢谢@Liero 指出这一点。


原答案

我也刚遇到这个问题,做了三件事解决了:

  1. 使用 .NET Core SDK(!- 不是运行时!)版本 2.0.0:

  2. 使用最新的 NuGet 源 (4.3.0):

  3. 恢复您的包:

更新 值得一提的是,您应该指定从何处获取 NuGet 包。大多数应用程序可能只使用 NuGet.org 提要,根据屏幕截图(请参阅小复选框),但您可以在 NuGet.config 文件中指定自定义提要。在这种情况下,勾选“Feeds in my NuGet.config”,然后指定该文件的路径。

为了说明顺序,这是我的工作队列:

我希望这对您和其他遇到此问题的人有所帮助。如果您有任何问题,请告诉我。 :)

【讨论】:

  • 在我的情况下,当我禁用 Use Nuget 4.3 (在我的情况下是4.*)时它也可以工作,但可能是因为该工具已被缓存。跨度>
  • 太棒了。朋友,我的帽子给你了!
  • 我仍然收到错误“错误:d:\a_tool\dncs\2.0.0\x64\dotnet.exe failed with return code: 1 Packages failed to restore”
  • @PankajRawat 你确定你使用的是最新版本的 nuget 并告诉它从 nuget.org 获取你的包(如果你没有包目录)?
  • @ChrisPaton 是的,我没有包目录。 s28.postimg.org/bj340omd9/Capture.jpg
【解决方案2】:

您应该选择我在此处选择的供稿作为供稿使用选项。如果您将使用此 VSTS/TFS 源中的软件包留空,则将从 https://dist.nuget.org/ 下载软件包。

否则,如果您想使用 我的 NuGet.config 中的提要作为提要使用,您应该指定 NuGet.config 文件的路径。

【讨论】:

  • 实际上,它适用于 .NET Core 任务 2.* (preview)1.*,但我必须添加 .NET Core Tool Installer 构建任务。难道是我的构建代理还没有更新?在恢复任务的2.* 中,我不得不取消选择“我的 Nuget.config 中的提要”,因为我没有。也许它可以默认为 nuget.org 包源?
  • 谢谢。然而,仅这一步是不够的。如果没有 .NET Core Tool Installer 构建任务,它在我的情况下不起作用。
  • 好的,既然你已经解决了问题,你可以为你的步骤添加一个答案并标记它。或者,如果您解决的步骤如克里斯在另一个答案中提到的那样,您可以标记他的答案。它也将使有类似问题的其他人受益。
【解决方案3】:

在使用dotnet new angular 创建项目后,我收到了类似的错误,该项目依赖于netcoreapp2.0。检查项目属性后发现 2.0 版本未被正确识别(未出现在已安装的框架列表中)。

解决方案是更新 Visual Studio 2017,因为支持 netcoreapp2.0 项目所需的最低版本似乎是 15.3.1

【讨论】:

    【解决方案4】:

    对我有用的是安装 .NET Core SDK 2.0 并进行以下更改:

    在 .csproj 中:

    改变

    <TargetFramework>netcoreapp1.1.0</TargetFramework>
    

    <TargetFramework>netcoreapp2.0</TargetFramework>
    

    在 global.json 中:

    "sdk": { "version": "1.1.0" }
    

    "sdk": { "version": "2.0.0" }
    

    我不知道如何使用 Chris Paton 的解决方案

    【讨论】:

      【解决方案5】:

      将 Visual Studio 2017 更新到最新的 15.4.1 版本解决了我的问题。

      【讨论】:

      • 你确定吗?因为这个问题与 VSTS 而不是 Visual Studio 有关?
      • 升级到 .netCore 2.0 后,我在 Visual Studio 构建中遇到了同样的错误。我有 Visual Studio 15.2 版。将 Visual Studio 更新到最新版本 15.4.1 后问题已解决
      猜你喜欢
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      相关资源
      最近更新 更多