154

We are moving our package management from manually updating files to NuGet. I am trying to install older versions of packages to match the one we already have in source control. There is no way to do this from the UI so I use the command line to get the proper version.

For some reason, Install-Package keeps on telling me that the nuget gallery is unreachable.

The source at nuget.org [https://www.nuget.org/api/v2/] is unreachable. Falling back to NuGet Local Cache

This happens only in one of our solutions. If I create a new solution or use another one in the same repository, packages will install as expected. I can even install the packages in a dummy solution to fill the local cache and then install them successfully in the faulty solution. I have tried to Invoke-WebRequest on the url from the NuGet Console and I get an HTTP 200.

What can cause this? Is there a way to override the package sources on a per solution/project basis?

Etienne Maheu
  • 3,235
  • 2
  • 18
  • 24
  • 3
    I'm having this same issue. I've installed the VS 2013 Update 2 yesterday, perhaps this is a new bug...? Btw, I can install any package through the "Manage NuGet Packages" dialog without problems, this issue only happens on the Package Manager Console. – rsenna Jun 05 '14 at 20:35
  • 2
    I've got the same problem. Always works in the Manage Packages dialog -- never works in Package Manager Console. – David Tansey Jun 26 '14 at 21:34
  • 10
    Restarting Visual Studio fixed this for me ಠ_ಠ – Chris Marisic Sep 08 '14 at 14:40

13 Answers13

340

Even though my Package Source was set to nuget.org in Package Manager Console, explicitly adding the -Source nuget.org argument fixed this for me.

So an example of use would be:

Install-Package Akka.net -Source nuget.org

Akka.net being your package that you want to install, its just an example here.

sellotape
  • 8,034
  • 2
  • 26
  • 30
  • 1
    I restarted my PC and Visual Studio. but.. adding -Source nuget.org indeed did the trick for my new .vbproj instance inside my existing multi-project .sln – bkwdesign Feb 27 '15 at 17:43
  • Where to add this argument and how? Can you please give more info. – Radenko Zec Apr 17 '15 at 06:58
  • It also worked for me (right now, actually!). I was trying to install an older version of jQuery, but it kept raising the error: "The source at nuget.org [https://www.nuget.org/api/v2/]". I don't know how to fix it though. – Loudenvier Jul 01 '15 at 17:17
  • thank you, i did this way: `Install-Package jQuery.UI.Combined -Source nuget.org` – Shaiju T Aug 30 '15 at 12:11
  • 7
    Do you have any idea how this works? I am just curious as this doesn't make any sense to me even if it works. So error says _The source at nuget.org [https://www.nuget.org/api/v2/] is unreachable_ and then I specify *same* source `-Source nuget.org` and it works? – Vladimirs Oct 22 '15 at 09:41
10

I had to copy the default NuGet source in Visual Studio's options. With the copied source, I changed the URL from https to http. This resolved the problem for me.

Credit for this suggestion belongs here: https://nuget.codeplex.com/discussions/561075#PostDetailsCell_1354351, to "jpharris4".

Zarepheth
  • 2,465
  • 2
  • 32
  • 49
7

You can change NuGet source from UI as well. Just change NuGet source to older version and it should work fine.

enter image description here

There seems to be still few bugs in VS 2015 related to api.nuget.org (v3).

Community
  • 1
  • 1
Sameer Azazi
  • 1,503
  • 10
  • 16
6

I'm not sure what can cause your issue, but there is indeed a way to override package sources on a per-solution basis, but only if you've enabled NuGet Package Restore on the given solution.

Once a solution has enabled NuGet Package Restore a folder called ".nuget" gets added to the solution. Under this will be a file called "NuGet.targets" that has an ItemGroup whose Condition is " '$(PackageSources)' == '' " like the one you'll see in the attached image.

If the ItemGroup is empty (or completely commented out, as in the illustration) then the solution will use a specific file that should be the same as the sources listed under TOOLS >> OPTIONS. But if you uncomment or add PackageSource items to that ItemGroup the solution will search the package sources listed and ONLY the ones listed.

Contents of the Nuget.targets file

  • 2
    Package sources defined in the NuGet.targets file only affect those used during build when a package is being restored. Package sources in the NuGet.config file in the .nuget directory will affect the package sources available to a project in Visual Studio. – Matt Ward Jun 04 '14 at 10:21
  • I do have package restore enabled for this solution. The ItemGroup is configured just as in your screenshot which I assume is the default setting so I do no think this is the issue. However, package restore have been enabled a significantly long time ago and the target file changed since then. I have tried updating those files to the latest version by deleting them and reenabling package restore and it looks like it solved the problem. – Etienne Maheu Jun 04 '14 at 14:43
  • Or not. It worked at first, but after restoring the packages for the solution and restarting visual studio, the issue came back. – Etienne Maheu Jun 04 '14 at 15:00
  • A few clarifying questions: 1) Do you have the proper versions referenced in packages.config? 2) Have you confirmed that the version you're looking for still exists on the [NuGet server](http://www.nuget.org/packages/NUnit/)? 3) Have you cleaned the solution and then rebuilt it after having completed 1) and 2)? – Omnidisciplinarianist Jun 10 '14 at 23:13
  • I know it's been a long time but I still wanted to provide a little update. In the end, this whole thing isn't fixed even today. I blame some network issue with my computer as no one else in the same project seems to have the problem. – Etienne Maheu Jul 25 '14 at 20:20
  • 1
    If it's any consolation - I get this issue but only on my work PC and it happens with most projects. The odd thing is that it's intermittent which drives me mad! – Matt Jul 30 '14 at 08:14
  • @EtienneMaheu, I wonder if this has to do with the local version of your nuGet package. That also might explain the intermittent nature of the issue. If that were the case, it would be a matter of seeing whether doing something like running "nuget.exe update -self" from the .nuget folder of your project. – Omnidisciplinarianist Sep 24 '14 at 17:56
2

In my Package Manager Console i could not see any sources

Going to: Tools -> Options -> Nuget Package Manager -> Package Sources

I found the sources. Unchecking them, and them checking them back made the re-appear in my Package Manager Console

roNog
  • 23
  • 5
2

I had to provide the comman along with the full url as Install-Package MySql.Data.Entity -Version 6.9.8 -Source http://www.nuget.org/api/v2

gavinfonseca
  • 33
  • 1
  • 5
1

In my case the cause was that the package had an agreement. Through the UI - "Manage NuGet Packages" dialog you have the option to accept and continue.

The Package Manager Console in VS 2013 seems to have an issue with this. As others have said restarting VS 2013 might resolve it for the console.

Byron
  • 691
  • 9
  • 9
1

This is worked for me in VS 2015 prof: Tools -> Options -> Nuget Package Manager -> Package Sources

  1. Press Add button
  2. Edit in Name label: nuget.org
  3. Edit in Source label: https://www.nuget.org/api/v2/
  4. Press OK

Hope it helps ;)

Husni Salax
  • 1,968
  • 1
  • 19
  • 29
  • For VS 2015 you should be using v3 of their list... not v2! Taken from their homepage NuGet feed v3 (VS 2015 / NuGet v3.x): https://api.nuget.org/v3/index.json NuGet feed v2 (VS 2013 and earlier / NuGet 2.x): https://www.nuget.org/api/v2 – Paul Zahra Dec 20 '16 at 14:14
0

I had the same issue with the same message. But the reason of my problem was lost connection to TFS. My TFS server was hosted in other network and I used VPN for access to it. When I tried to install the package without established connection to TFS (VPN was turned off) I got the same problem.

Be aware of this TFS behavior.

RredCat
  • 5,259
  • 5
  • 60
  • 100
0

Happens because you work offline mode, when you reconnect the network will need to log off and log back. Package manager will smoothly re-initialize.

0

I have faced this issue VS2013 and wasted 3 hours of time.

Not Sure what was the cause of the issue. But none of the above solutions worked for me.

Re-Installtion of Nuget Package Manager console worked for me.

Tools - > Extensions and Updates -> Under All Look for Nuget Package Manager for Visual Studio and hit uninstall.

Go to https://marketplace.visualstudio.com/items?itemName=NuGetTeam.NuGetPackageManagerforVisualStudio2013 and download the extension.

Syed Abbas
  • 49
  • 1
  • 8
0

enter image description hereMay be yours office/home firewall blocking nuget.org so try to connect different internet network for example from your mobile or wifi .I was able to solve through this method.

0

None of these solutions worked for me with VS2013. Yes I know it's the year 2020. In the end I downloaded the nuget package to a local folder, added the folder to the nuget settings, and then voila!, was able to install the package.

RonnieScotland
  • 132
  • 2
  • 5