简体   繁体   English

VSTS:nuget.exe 失败并返回代码:1 包无法恢复

[英]VSTS: nuget.exe failed with return code: 1 Packages failed to restore

I am new in Visual Studio 2017 and was trying to build using Visual Studio Team Services.我是 Visual Studio 2017 的新手,我正在尝试使用 Visual Studio Team Services 进行构建。 I am getting the following error:我收到以下错误:

System.AggregateException: One or more errors occurred. ---> NuGet.Protocol.Core.Types.FatalProtocolException: Failed to retrieve information about 'Microsoft.AspNetCore' from remote source 'http://nuget.ohyeah.net/api/v2/FindPackagesById()?id='Microsoft.AspNetCore''. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The remote name could not be resolved: 'nuget.ohyeah.net'

I was googling to make sure I know why exactly this error happens but no luck yet.我正在谷歌搜索以确保我知道为什么会发生此错误,但还没有运气。 A sample stack trace can be found here: https://pastebin.com/RiGmd7Cd可以在此处找到示例堆栈跟踪: https : //pastebin.com/RiGmd7Cd

What could be the reason, is it because of some settings in Nuget.Config?可能是什么原因,是因为 Nuget.Config 中的某些设置吗? It looks exactly like below:它看起来完全像下面:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <disabledPackageSources />
  <packageSources>
    <add key="3rdparty" value="http://nuget.XXX.net/api/v2/" />
    <add key="official" value="http://nuget.XXX.net/api/v2/" />
      <add key="vsts-official" value="https://XXXXXX.pkgs.visualstudio.com/_packaging/Official/nuget/v3/index.json" />
    <!--<add key="local" value="C:\inetpub\wwwroot\Packages" />-->
    <add key="microsoft" value="https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/" />
    <add key="nuget.org" value="" />
  </packageSources>
</configuration>

I am stuck on this, any help would be highly appreciated.我坚持这一点,任何帮助将不胜感激。

First, check nuget.ohyeah.net can be accessible from build agent. 首先,检查nuget.ohyeah.net可以从构建代理访问。

Secondly, you need to check Nuget.config file whether https://api.nuget.org/v3/index.json is in the package sources, if not add it: 其次,您需要检查Nuget.config文件是否在包源中包含https://api.nuget.org/v3/index.json ,如果没有添加的话:

<packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
  1. Project root folder if it existing in. 项目根文件夹(如果存在)。
  2. The Nuget config file if you specified in NuGet Restore task 如果在NuGet Restore任务中指定了Nuget配置文件
  3. Build service user folder on build agent(%appdata%\\Nuget) 构建代理上的构建服务用户文件夹(%appdata%\\ Nuget)

BTW, the code you provided is not for Nuget.Config, it is NuGet package file. 顺便说一句,您提供的代码不是用于Nuget.Config的,而是NuGet软件包文件。

It looks like you have a package source configured somewhere. 看来您已在某处配置了软件包源。 Either in VSTS or a Nuget.Config. VSTS中或Nuget.Config中。 Based on the log, you have a custom source ' http://nuget.ohyeah.net/ ' which is not a valid nuget feed. 根据日志,您有一个自定义源' http://nuget.ohyeah.net/ ',它不是有效的nuget提要。 If you have more details about your configuration, it would be easier to assist. 如果您有关于配置的更多详细信息,则将更容易提供帮助。

The problem was mixing the old TFS xml formatted resource and json formatted VSTS resources. 问题是将旧的TFS xml格式的资源和json格式的VSTS资源混合在一起。 So, in this particular problem, VSTS will always look for id to be matched in a json file to match to a nuget package, then VSTS will try to retrieve the nuget packages. 因此,在这个特定问题中,VSTS始终会在json文件中寻找要匹配的id以匹配nuget包,然后VSTS会尝试检索nuget包。 If you have old TFS nuget repositories, you have to create an entry in a json file. 如果您有旧的TFS nuget存储库,则必须在json文件中创建一个条目。 In my case, I had to remove the old TFS packageSources like http://nuget.XXX.net/api/v2/ from Nuget.Config. 就我而言,我必须从Nuget.Config中删除旧的TFS软件包源,例如http://nuget.XXX.net/api/v2/ Also, you need to create a valid @id , @type dictionary entry in your new json file, in my case it is: https://XXXXXX.pkgs.visualstudio.com/_packaging/Official/nuget/v3/index.json . 此外,您还需要创建一个有效的@id@type在新的JSON文件字典条目,在我的情况是: https://XXXXXX.pkgs.visualstudio.com/_packaging/Official/nuget/v3/index.json Now, the working version looks like below: 现在,工作版本如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <disabledPackageSources />
  <packageSources>
      <add key="vsts-official" value="https://XXXXXX.pkgs.visualstudio.com/_packaging/Official/nuget/v3/index.json" />
    <add key="microsoft" value="https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/" />
    <add key="nuget.org" value="" />
  </packageSources>
</configuration>

The easiest solution to this just change version of NuGet package as shown below.最简单的解决方案就是更改 NuGet 包的版本,如下所示。 I have faced the same issue when NuGet restore searching for V 3.3.0.在 NuGet 还原搜索 V 3.3.0 时,我遇到了同样的问题。 It was there, I used it I hosted agent.它在那里,我用它托管代理。 I found this have worked for me.我发现这对我有用。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM