团队服务构建中的 nuget 恢复失败

nuget restore failing in team services build

我在 asp.net 核心解决方案上使用 vs2017 通过 nuget 引用了 2 个本地程序集(打包了 dll),在本地构建良好。

现在尝试通过 VSTS 生成构建时出现以下错误,

Detected NuGet version 4.0.0.2283 / 4.0.0
SYSTEMVSSCONNECTION exists true
Saving NuGet.config to a temporary config file.
d:\a\_tool\NuGet.0.0\x64\nuget.exe restore d:\a\s\TestFrameworkCoreAPI.sln -Verbosity Detailed -NonInteractive -ConfigFile d:\a\Nuget\tempNuGet_37.config
NuGet Version: 4.0.0.2283
MSBuild auto-detection: using msbuild version '15.3.409.57025' from 'C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
MSBuild P2P timeout [ms]: 120000
C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\bin\msbuild.exe /t:GenerateRestoreGraphFile /nologo /nr:false /p:RestoreUseCustomAfterTargets=true /p:BuildProjectReferences=false /v:q  /p:NuGetRestoreTargets="d:\a\_temp\NuGet-Scratch\w53qa5rr.4sd.targets" /p:RestoreTaskAssemblyFile="d:\a\_tool\NuGet.0.0\x64\nuget.exe" /p:RestoreGraphOutputPath="d:\a\_temp\NuGet-Scratchmlmlfgh.mmy.result" /p:ExcludeRestorePackageImports=true  /p:RestoreRecursive=False  /p:RestoreProjectFilterMode=exclusionlist /p:RestoreContinueOnError=WarnAndContinue  /p:RestoreGraphProjectInput="d:\a\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj;" "d:\a\_temp\NuGet-Scratch\w53qa5rr.4sd.targets"
Running restore with 2 concurrent jobs.
Reading project file d:\a\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj.
Reading project file d:\a\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj.
Restoring packages for d:\a\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj...
Restoring packages for d:\a\s\TestFrameworkCoreAPI\TestFrameworkCoreAPI.csproj...
Restoring packages for .NETCoreApp,Version=v1.1...
Restoring packages for .NETCoreApp,Version=v2.0...
System.AggregateException: One or more errors occurred. ---> NuGet.Protocol.Core.Types.FatalProtocolException: Failed to retrieve information about 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' from remote source 'D:\TestFrameworkAssemblies'.
   at NuGet.Protocol.LocalV3FindPackageByIdResource.GetVersionsCore(String id, ILogger logger)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at NuGet.Protocol.LocalV3FindPackageByIdResource.GetAllVersionsAsync(String id, SourceCacheContext cacheContext, ILogger logger, CancellationToken token)
   at NuGet.Commands.SourceRepositoryDependencyProvider.<FindLibraryAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
Error: d:\a\_tool\NuGet.0.0\x64\nuget.exe failed with return code: 1
Packages failed to restore

我在位于解决方案根目录的 .nuget 文件夹中有一个 nuget.config 文件,

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
  <!-- remove any machine-wide sources with <clear/> -->
  <clear />
  <add key="Test Framework" value="D:\TestFrameworkAssemblies" />
  <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<activePackageSource>
    <add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>     

这是 VSTS 构建定义中的内容,NuGet 还原步骤

它看起来总是引用我的本地程序集而不是标准 nuget.org,现在在配置文件中,如果我取出框架程序集的本地条目,nuget 部分可以工作,但我得到一个主要的引用错误,因为它找不到我在本地打包的 2 个程序集。

目前一直在兜圈子,如何让 VSTS 恢复本地打包程序集以及 nuget.org。我也在使用 Hosted 2017。

提前致谢

您似乎正在对托管代理上的构建进行排队。由于在您的本地计算机上有这些软件包,您应该 使用位于您本地计算机上的 private agent 构建 .

此外,如果您需要在 Hosted agent 上排队构建,您应该在存储库中添加本地包,然后使用新路径引用包并更改 nuget.config 中的值。