【问题标题】:"Unable to find version" during TFS Build 2015 when restoring NuGet packages还原 NuGet 包时在 TFS Build 2015 期间“找不到版本”
【发布时间】:2015-12-02 18:02:18
【问题描述】:

在 TFS Build 2015 期间,我在恢复 NuGet 包时遇到问题。

由于某些软件包需要 NuGet 3.x 客户端,我已将新的可编写脚本的构建配置为使用自定义 NuGet 位置,我已在其中放置了 NuGet 命令行 3.x 测试版的可执行文件 .

每当我运行构建时,所有包都无法恢复,并且 NuGet 会抛出 “无法找到版本...” 错误:

Unable to find version '1.1.10' of package 'Microsoft.Bcl'.
Unable to find version '4.0.10' of package 'System.Threading'.
Unable to find version '1.1.37' of package 'System.Collections.Immutable'.
Unable to find version '1.0.0' of package 'Owin'.
Unable to find version '4.1.0' of package 'NLog'.
Unable to find version '7.0.1' of package 'Newtonsoft.Json'.
Unable to find version '2.0.1' of package 'MongoDB.Driver.Core'.
Unable to find version '2.0.1' of package 'MongoDB.Driver'.
Unable to find version '2.0.1' of package 'MongoDB.Bson'.
Unable to find version '3.0.1' of package 'Microsoft.Owin.Security.OAuth'.

...甚至更多的软件包。我相信这个问题很清楚。

当我使用 Visual Studio 在构建机器中构建相同的解决方案时,所有包都已成功恢复。

我该如何解决这个问题?

【问题讨论】:

  • 您是否安装了任何 Microsoft.CodeAnalysis NuGet 包?我做到了,我开始遇到这些错误,当我删除所有这些错误时,它又开始工作了。
  • @Schenz 我没有这个 NuGet 包

标签: visual-studio tfs nuget visual-studio-2015 tfs-2015


【解决方案1】:

在我的例子中,问题是位于C:\Users\[User name]\AppData\Roaming\NuGet\NuGet.config 的用户范围的NuGet.config(其中[User name] 是运行构建代理的Windows 服务的用户)指向NuGet API v2 while my build is already using NuGet Command-Line 3.x。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <!-- CHANGING V2 TO V3 IN THE URI VALUE SOLVED THE ISSUE! -->
    <add key="nuget.org" value="https://www.nuget.org/api/v3/" />
  </packageSources>
</configuration> 

【讨论】:

  • 我遇到了类似的问题,但仅在尝试通过包管理器控制台安装包时;包管理器对话框工作正常。这个答案为我指明了正确的方向:它是包源的 URL。在我的例子中,Nuget.config 中的 URL 是 "https://www.nuget.org/api/v2/"。当我删除“www”时,将其更改为"https://nuget.org/api/v2/" 它起作用了。
  • nuget.org/api/v3 -- 此位置不存在(api.nuget.org/v3/index.json 存在)...并且此处定义的两个键都具有相同的 ID(“nuget.org”)
  • 在我的例子中,第 3 个版本已经在配置中指向了。我刚刚删除了配置文件的所有内容,它有所帮助:
【解决方案2】:

就我而言,Nuget.Config 位于:

C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\NuGet

所以在您的C:\ 中搜索Nuget.Config。

用户取决于您配置Agent的帐户

【讨论】:

    【解决方案3】:

    如果由于某种原因更新漫游文件夹中的NuGet.config 不是一个选项或不需要,也可以将配置文件添加到解决方案根目录。

    根据文档:

    • 项目特定的 NuGet.Config 文件位于从解决方案文件夹到驱动器根目录的任何文件夹中。这些允许在应用于项目或项目组时控制设置。
    • 解决方案特定的 NuGet.Config 文件位于解决方案的 .nuget 文件夹中。此文件中的设置仅适用于解决方案范围的包,并且仅在 NuGet 3.3 及更早版本中受支持。 NuGet 3.4 及更高版本将忽略它。

    Config file locations and uses

    【讨论】:

    • 不错的补充。根据具体情况,这个问题似乎有很多变通方法/解决方案!
    【解决方案4】:
    1. 您的项目文件夹必须包含“packages”文件夹,并且在该“packages”文件夹中应该存在所有包 dll。
    2. 您的项目引用应该指向这些包 dll。

    【讨论】:

      猜你喜欢
      • 2015-10-11
      • 1970-01-01
      • 2016-08-23
      • 2020-10-05
      • 1970-01-01
      • 2023-03-04
      • 2017-12-04
      • 2014-06-17
      • 1970-01-01
      相关资源
      最近更新 更多