1

While installing the NuGet packages from the NuGet package manage, having configured multiple NuGet package sources in VS2017, the NuGet client tries to retrieve the package in all the configured NuGet sources and returns messages like "Not Found".

I have configured the below NuGet sources in my NuGet.Config,

Available NuGet sources

I have tried to restore the Newtonsoft.Json NuGet package from the command prompt by using the nuget restore command. The NuGet client will try to retrieve the Newtonsoft.Json NuGet package from my custom NuGet feed, which does not contain the Newtonsoft.Json package and returns a NotFound message in the output:

Not found error

However the package is restored perfectly without issues. But why does the package manager search all the sources which are configured and prints not found errors even it found it in the first NuGet source?

Why does the NuGet client try to retrieve in all configures sources? Is this a bug from NuGet? I am using Visual Studio 2017 (15.4) and NuGet package Manager (4.4.0).

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • hm looks strange, try installing using nuget package manager instead of using command – Venkatesh Konatham Oct 27 '17 at 10:30
  • @VenkateshKonatham - Thanks for the update. That seems correct but, we need to automate this in our build server. So that we have asked about command line restore. – user2473950 Oct 27 '17 at 10:35
  • hmm that's strange behavior, On your server if you have visual studio then rebuilding the project will download it, If its not doing it you can do one thing remove the package and reinstall it from nuget window then take latest on server and then check it – Venkatesh Konatham Oct 27 '17 at 11:03
  • @VenkateshKonatham - Thanks. This query is not related to install/restoring the package. This is related to why the packages searched all the configured packages sources and returned 404 error. – user2473950 Oct 30 '17 at 05:33

1 Answers1

3

No, it's not a bug.

When the NuGet client is doing a restore and sees you have a dependency on some package, it has no way of knowing which feed the package exists in. In the past, the NuGet client would query each source in order, but at some point it was changed to query all sources concurrently and use the first successful response.

There are also several scenarios where you would want to get a package that is available on nuget.org, from a source other than nuget.org. One example is you might have a private feed with commonly used packages on the same network as your build servers, so that package restore is as quick as possible and more resilient to network outages.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
zivkan
  • 12,793
  • 2
  • 34
  • 51
  • Okay, but if you're looking to install EntityFramework and you have Nuget and PowershellGallery as package source, but in the package manager in VS 2022 you have Nuget selected for the package source, why does it still search PowershellGallery? – Jacques Jan 14 '22 at 14:28
  • When you search it shouldn't search multiple feeds, only the one you have selected in the dropdown. However, when you install, it tries all feeds just like when it restores, unless you use Package Source Mapping, a new feature in VS2022. A fundamental design point of nuget is that package versions are globally unique and immutable. Even with package source mapping this assumption is still important because once the package-version is in your packages folder, it will never try to re-download, even if a different solution uses a different feed for the same package. – zivkan Jan 15 '22 at 06:01
  • Apologies, quite right the search itself only returns items from the selected source, but it's during installation when things go wrong. Are you saying that the only way to solve the problem then is to switch off the other feeds, in my case PowerShellGallery? – Jacques Jan 17 '22 at 06:51