18

在 TFS Build 2015 期间,我在还原 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

4 回答 4

23

在我的情况下,问题是NuGet.config位于C:\Users\[User name]\AppData\Roaming\NuGet\NuGet.config(运行构建代理的 Windows 服务的用户在哪里[User name])的用户范围指向 NuGet API v2 ,而我的构建已经在使用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> 
于 2015-09-07T08:44:54.940 回答
3

就我而言,Nuget.Config, 位于:

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

所以Nuget.Config在你的C:\.

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

于 2016-07-14T21:31:09.290 回答
2

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

根据文档:

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

配置文件位置和用途

于 2017-04-28T13:48:11.590 回答
0
  1. 您的项目文件夹必须包含“包”文件夹,并且在该“包”文件夹中应该存在所有包 dll。
  2. 您的项目引用应该指向这些包 dll。
于 2020-06-17T15:38:20.283 回答