"Unable to find version" 在 TFS Build 2015 期间恢复 NuGet 包时
"Unable to find version" during TFS Build 2015 when restoring NuGet packages
我在 TFS Build 2015 期间遇到 NuGet 包恢复问题。
由于某些软件包需要 NuGet 3.x 客户端,我已经配置了新的可编写脚本的构建以使用自定义 NuGet 位置,我已将 NuGet 命令行 3.x测试版.
每当我 运行 构建时,所有包都无法恢复,NuGet 会抛出 "Unable to find version..." 错误:
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 在构建机器中构建相同的解决方案时,所有包都已成功恢复。
我该如何解决这个问题?
在我的例子中,问题是用户范围 NuGet.config
位于 C:\Users\[User name]\AppData\Roaming\NuGet\NuGet.config
(其中 [User name]
是 运行 构建代理的 Windows 服务)指向 NuGet API v2 .
<?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>
在我的例子中,Nuget.Config
位于:
C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\NuGet
所以在 C:\
中搜索 Nuget.Config
。
用户取决于您配置的帐户 Agent
如果出于某种原因更新漫游文件夹中的 NuGet.config
不是一个选项或不需要,也可以将配置文件添加到解决方案根目录。
根据文档:
- 项目特定 NuGet.Config 文件位于从解决方案文件夹到驱动器根目录的任何文件夹中。这些允许控制应用于一个项目或一组项目的设置。
- 特定于解决方案的 NuGet.Config 文件位于解决方案的 .nuget 文件夹中。此文件中的设置仅适用于解决方案范围的包,并且仅在 NuGet 3.3 及更早版本中受支持。 NuGet 3.4 及更高版本将忽略它。
- 您的项目文件夹必须包含 'packages' 文件夹,并且在该 'packages' 文件夹中应该存在所有包 dll。
- 您的项目引用应指向那些包 dll。
我在 TFS Build 2015 期间遇到 NuGet 包恢复问题。
由于某些软件包需要 NuGet 3.x 客户端,我已经配置了新的可编写脚本的构建以使用自定义 NuGet 位置,我已将 NuGet 命令行 3.x测试版.
每当我 运行 构建时,所有包都无法恢复,NuGet 会抛出 "Unable to find version..." 错误:
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 在构建机器中构建相同的解决方案时,所有包都已成功恢复。
我该如何解决这个问题?
在我的例子中,问题是用户范围 NuGet.config
位于 C:\Users\[User name]\AppData\Roaming\NuGet\NuGet.config
(其中 [User name]
是 运行 构建代理的 Windows 服务)指向 NuGet API v2
<?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>
在我的例子中,Nuget.Config
位于:
C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\NuGet
所以在 C:\
中搜索 Nuget.Config
。
用户取决于您配置的帐户 Agent
如果出于某种原因更新漫游文件夹中的 NuGet.config
不是一个选项或不需要,也可以将配置文件添加到解决方案根目录。
根据文档:
- 项目特定 NuGet.Config 文件位于从解决方案文件夹到驱动器根目录的任何文件夹中。这些允许控制应用于一个项目或一组项目的设置。
- 特定于解决方案的 NuGet.Config 文件位于解决方案的 .nuget 文件夹中。此文件中的设置仅适用于解决方案范围的包,并且仅在 NuGet 3.3 及更早版本中受支持。 NuGet 3.4 及更高版本将忽略它。
- 您的项目文件夹必须包含 'packages' 文件夹,并且在该 'packages' 文件夹中应该存在所有包 dll。
- 您的项目引用应指向那些包 dll。