Sharif Mamun
Sharif Mamun

Reputation: 3554

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. 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

What could be the reason, is it because of some settings in 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.

Upvotes: 2

Views: 23750

Answers (4)

Bappa Aditya Shee
Bappa Aditya Shee

Reputation: 41

The easiest solution to this just change version of NuGet package as shown below. I have faced the same issue when NuGet restore searching for V 3.3.0. It was there, I used it I hosted agent. I found this have worked for me.

enter image description here

Upvotes: 2

Sharif Mamun
Sharif Mamun

Reputation: 3554

The problem was mixing the old TFS xml formatted resource and json formatted VSTS resources. 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. If you have old TFS nuget repositories, you have to create an entry in a json file. In my case, I had to remove the old TFS packageSources like http://nuget.XXX.net/api/v2/ from Nuget.Config. 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. 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>

Upvotes: 1

starian chen-MSFT
starian chen-MSFT

Reputation: 33698

First, check nuget.ohyeah.net can be accessible from build agent.

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:

<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
  3. Build service user folder on build agent(%appdata%\Nuget)

BTW, the code you provided is not for Nuget.Config, it is NuGet package file.

Upvotes: 3

DenverDev
DenverDev

Reputation: 497

It looks like you have a package source configured somewhere. Either in VSTS or a Nuget.Config. Based on the log, you have a custom source 'http://nuget.ohyeah.net/' which is not a valid nuget feed. If you have more details about your configuration, it would be easier to assist.

Upvotes: 1

Related Questions