在恢复NuGet包时,在TFS Build 2015期间“无法找到版本”

时间:2015-09-07 08:34:33

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

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

由于某些软件包需要NuGet 3.x客户端,我已经将新的脚本化构建配置为使用自定义NuGet位置,其中我放置了 NuGet Command-Line 3.x beta 的可执行文件

每当我运行构建时,所有软件包都无法恢复,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在构建计算机中构建相同的解决方案时,所有包都可以成功恢复。

我该如何解决这个问题?

4 个答案:

答案 0 :(得分:22)

就我而言,问题是位于NuGet.config的用户范围C:\Users\[User name]\AppData\Roaming\NuGet\NuGet.config(其中[User name]是运行构建代理的Windows的用户service)指向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> 

答案 1 :(得分:3)

在我的情况下,Nuget.Config位于:

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

因此,请在Nuget.Config中搜索C:\

用户取决于您配置Agent

的帐户

答案 2 :(得分:1)

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

根据文件:

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

Config file locations and uses

答案 3 :(得分:0)

  1. 您的项目文件夹必须包含“ packages”文件夹,并且在该“ packages”文件夹中应该存在所有软件包dll。
  2. 您的项目引用应指向那些软件包dll。