41

I am trying to restore the missing nuget packages and it keeps giving me this Error:

An error occurred while trying to restore packages. Please try again.

Any experience solving this? How can I find out what exactly is causing the error?

user3311522
  • 1,638
  • 3
  • 19
  • 33

15 Answers15

32

This is how I fix my issue:

First, I clear my Package Cache:

enter image description here

Second, I make sure I have the right path source and click the available package source:

enter image description here

Willy David Jr
  • 8,604
  • 6
  • 46
  • 57
22
  1. Make sure you upgrade to the latest NuGet (http://docs.nuget.org/docs/start-here/installing-nuget).
  2. Make sure you're doing package restore "The Right Way" http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

That should resolve the issue.

Ben
  • 1,853
  • 19
  • 20
Haacked
  • 58,045
  • 14
  • 90
  • 114
12

I had a similar issue with the Microsoft.Bcl.Build.1.0.14 NuGet package. My solution to this was to

  1. Close Visual Studio
  2. Remove the package folder with Explorer (or better only move it to another location)
  3. Start Visual Studio
  4. Go to the NuGet package manager and click Restore
testing
  • 19,681
  • 50
  • 236
  • 417
10

If you don't want the package, just double-click your packages.config, find the line which refers to the package you want to get rid of, and delete that line.

Then, if you do want the package you could probably just redownload it using nuget and it'd probably resolve itself.

Jared Beach
  • 2,635
  • 34
  • 38
  • 1
    Thank you for your suggestion, helped me with this same error. Though it would be nice to know the real reason why Nuget package restore failed. In my case I tried to restore Entity Framework 6.1.3 and it failed. Trying to then remove the line for EF in packages config and reapplying Install-Package EntityFramework gave me version 6.2.0 of EF. So I guess the version 6.1.3 of EF could not be found. – Tore Aurstad Jun 04 '18 at 12:59
4

I resolved the same issue by downloading the latest version of NuGet (really easy install, quick download): http://docs.nuget.org/docs/start-here/installing-nuget

Ben
  • 1,853
  • 19
  • 20
2

(Definitely a beginner's answer here, but I'll leave it since I didn't find this anywhere else.) Make sure that nuget.org hasn't been unchecked from your package sources.

Tools. Options. Nuget package manager. Package sources. Ensure "nuget.org" is checked.

Patrick
  • 1,227
  • 14
  • 17
2

The problem in my case

In my case, we have developed our own NuGet packages. For some indescribable reason when I opened the solution, When I open solution, that has a previous version of NuGet packages that is deleted from origin or removed or unreachable for any reason. This make it unable to build the projects containing specific NuGet packages. I tried to install/reinstall/upgrade the NuGet package with out luck getting following error (see the image below), I did also try all possible answers here, and ensured the package was there, but no luck.

An error occurred while trying to restore packages: Unable to find version xxx..etc.

enter image description here

The solution for my case

  • Close your solution and find the path of the solution

  • Open all your projects .csproj files with notepad editor, that contain the packages that have the issue and remove all references that is shown in the error message, looks like this and save:

    <Reference Include="Xxx, Version=30.0.0.16927, Culture=neutral, processorArchitecture=MSIL">
        <HintPath>..\packages\Xxx.35.1.122605\lib\net461\Xxx.dll</HintPath>
    </Reference>
    
  • In each folder where your .csproj is located, you find packages.config file, open it with notepad editor and remove all packages that is shown in the error message, looks like this and save:

    <package id="Xxx" version="35.1.122605" targetFramework="net461" />
    
  • Start your solution, the error now should disappear, but you can not build because we have removed references and packages. So now you should be able to install your missing packages in fresh. When done build and all should work. Enjoy :)

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
2

i fix this problem by moving the project folder to another one with less characters (local path was to long) i hope it helps some one

elblogdelbeto
  • 116
  • 1
  • 5
  • Definitely helped, thanks! In my case, Microsoft's vended Google Test package's name was far too long. Ended up just moving the project to the highest directory possible – DragonJawad Oct 03 '21 at 17:07
  • same here, i think there must be an issue if the path is too long – Mick P Aug 28 '23 at 09:23
1

I had similar issue, i found out it was due to my nuget cache.

Command to clear cache: dotnet nuget locals all --clear

After cache is cleared try restoring.

Shrivallabh
  • 2,863
  • 2
  • 27
  • 47
0

For me I cloned a solution (vs2015/NuGet3.4) that had a nuget dependency on a pre-release package that had been superceded. Nuget failed to restore the pre-release and wouldn't let me either uninstall or upgrade it. I frigged it by manually editting packages.config to target an older non-pre-release of the package, which I could then upgrade to the version I wanted. HTH

timB33
  • 1,977
  • 16
  • 33
0

Just in case it helps someone else, I had this issue in a .NET Standard project where I had defined the target frameworks incorrectly:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard1.3;netstandard2.0;net45</TargetFramework>
    </PropertyGroup>
    ...

When it should have been the plural TargetFrameworks (not TargetFramework):

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFrameworks>netstandard1.3;netstandard2.0;net45</TargetFrameworks>
    </PropertyGroup>
    ...

TheCrimsonSpace
  • 188
  • 1
  • 8
0

For me non of those things mentioned above work. I solved this issue by deleting packages.config in each project of my solution and then reinstalling all Nuget packages

Kebechet
  • 1,461
  • 15
  • 31
0

In my case, I had another package source added which was like this.

enter image description here

I just removed this source from the NuGet package manager and rebuild the solution, it started working for me.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
0

I ran into an error like this, but only when building a project with devenv. I had to use the /Out parameter to log build output which just said it couldn't restore NuGet packages. It turned out that we had two projects (*.csproj) named the same in the solution (*.sln). Somehow the project had been misconfigured and the simplest thing was to remove both duplicated projects and then add the actual project file to the solution fresh.

-2

Go to TOOLS under OPTIONS select NuGet Package Manager

  1. General, Select Everything
  2. Package Source, Select all required Source

Hit OK. Done you must be good to go.

GSKKC
  • 45
  • 6