22
votes

We are using the improved Automatic Package Restore process to restore missing NuGet packages.

When building, the Restore dialog pops up as it starts to download from the package sources, which is correct:

Restore Dialog

I can see that the packages are being restored into the packages folder, but it doesn't finish restoring all of them. I get the following kind of errors:

Error   10  NuGet Package restore failed for project MyProject: System.InvalidOperationException: Unable to find version '6.0.1' of package 'Newtonsoft.Json'.
   at NuGet.PackageHelper.ResolvePackage(IPackageRepository repository, String packageId, SemanticVersion version)
   at NuGet.VsEvents.PackageRestorer.RestorePackage(PackageReference package)
   at NuGet.VsEvents.PackageRestorer.RestorePackages(String packageReferenceFileFullPath, IFileSystem fileSystem)
   at NuGet.VsEvents.PackageRestorer.PackageRestore(ProjectPackageReferenceFile projectPackageReferenceFile).

Could this be because I have multiple package sources?

enter image description here

NuGet may be searching in our private package source for the 'Newtonsoft.Json', for example, and not in the nuget.org source.

The .nuget/NuGet.config file:

<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="private" value="http://privatePackageSource.com/nuget" />
  </packageSources>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
</configuration>

We are using Visual Studio 2013 and NuGet 2.8.5.

EDIT:

Using Fiddler, I have confirmed that NuGet is indeed searching for the packages in the incorrect source. It is requesting the following packages from my private repository.

I also read this post and added the activePackageSource section to the NuGet.config file:

<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="private" value="http://privatePackageSource.com/nuget" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
</configuration>

But it doesn't fix the problem.

3
What do you have in your global NuGet.config file (C:\Users\UserName\AppData\Roaming\NuGet\NuGet.config)? If you have the private package source defined in there but disabled it will override your solution's NuGet.config. Check that first. If so you can override the global NuGet.config by using a <clear /> element in your solution's NuGet.config file.Matt Ward
It is also defined there (I don't understand how?) but it is not set as disabled.Dave New
If you make changes to your settings whilst your solution NuGet.config is loaded then NuGet will save the package source into the global NuGet.config. If you remove it from the global NuGet.config is the private package source visible in the Manage Packages dialog?Matt Ward
@MattWard: The global NuGet.config was indeed the problem. It wasn't up to date. Create an answer and I will reward it - thanks.Dave New

3 Answers

18
votes

It was indeed being overridden by the global NuGet.config file (C:\Users\UserName\AppData\Roaming\NuGet\NuGet.config). Restarting Visual Studio seemed to clear it.

11
votes

For some reason, my NuGet.config had nuget.org key disabled. I checked the NuGet Package Manger settings and everything was correct. Restarted VS2013 and it worked. Here is my NuGet.config that works:

<?xml version="1.0" encoding="utf-8"?>
 <configuration>
  <solution>
   <add key="disableSourceControlIntegration" value="true" />
  </solution>
 <packageRestore>
  <add key="enabled" value="True" />
  <add key="automatic" value="True" />
 </packageRestore>
 <packageSources>
   <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
 </packageSources>
 <disabledPackageSources />
 <activePackageSource>
   <add key="Microsoft and .NET" value="https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/" />
 </activePackageSource>
</configuration>
1
votes

Had the same error, in my case a nuget restore command before building fixed it for me