35

When I try to compile my program I get the following error:

This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567.    

Now when I right click on the solution and press

All packages are already installed and there is nothing to restore.

I tried manually reinstalling every package which didn't solve the problem, I tried reinstalling NuGet but that didn't help either and I even tried reinstalling visual studio.

I also tried moving the package folder from the tfs folder to overwrite my package folder but that didn't solve anything. I also tried redownloading them with this package missing, that didn' t solve the problem either.

Anybody know how to restore the nuget packages?

Thijser
  • 2,625
  • 1
  • 36
  • 71

9 Answers9

31

Use Package Manager Console in Visual Studio to run this command.

1.This will restore all packages from solution

nuget restore YourSolution.sln

2.If you want to reinstall the packages to the same versions as were previously installed

Update-Package -reinstall
Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54
  • nuget restore TestEnvi.sln give me the error The term 'restore' is not recognized as the name of a cmdlet, function, script – Thijser Jun 28 '16 at 11:20
  • That suggests that installing nuget commands would be simply running Install-Package NuGet.CommandLine but that gives me 'Package 'NuGet.CommandLine.3.4.3' already exists in project 'TestEnvi'' – Thijser Jun 28 '16 at 11:27
  • Did you try `Update-Package -reinstall` command in package manager console – Rahul Nikate Jun 28 '16 at 11:27
  • That runs for a bit and then throws the error ' The item 'packages.config' cannot be deleted ' – Thijser Jun 28 '16 at 11:29
  • 2
    There's one work around for this. In your solution folder there should be a "packages" directory. Open this directory and delete all the directories and then run again reinstall. – Rahul Nikate Jun 28 '16 at 11:31
  • Hmm running it a second time it did complete, but I still canot run the restore command (nuget not recognized) and the problem persitsts. – Thijser Jun 28 '16 at 11:32
  • Try deleting whole `packages` folder from solution and then run `Update-Package -reinstall` – Rahul Nikate Jun 28 '16 at 11:32
  • An unexpected error is keeping you from deleting the folder. if you continue to receive this error you can use the error code to search for help with this problem. Error 0x8007000F: The system cannot find the drive specified. So I cannot delete the folder in question – Thijser Jun 28 '16 at 11:33
  • I doubt you have file access permissions issue or corrupted drive. You need to check your OS and computer system. It has nothing to do with nuget – Rahul Nikate Jun 28 '16 at 11:36
  • Any advice how to deal with these? The file sits on an veracrypt encrypted file so shouldn' t that sort of auto detect problems? – Thijser Jun 28 '16 at 11:37
  • You need to check your OS and computer system. It has nothing to do with nuget. sorry its out of my knowledge. – Rahul Nikate Jun 28 '16 at 11:38
  • I will if it turns out that this is indeed the problem. I'm currently looking into the filesystem. But it looks like this is going to help seeing as how there are 3 files that cannot be removed as a admin cmd. – Thijser Jun 28 '16 at 11:44
  • I managed to remove the packages folder (had to specify thoese 3 files by hand) and when ran the program which resulted in the package folder being downloaded again. However the problem remains unchanged. – Thijser Jun 28 '16 at 11:51
  • 5
    The command `nuget restore mysolution.sln` doesn't work for me in the Package Manager Console window, I get this error: "`PM> nuget restore reco.sln nuget : The term 'nuget' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.`" – Dai Feb 24 '17 at 21:01
  • This worked partly, I also had to add references manually, it was a mix of all the steps – Legends Nov 30 '17 at 00:10
  • 2
    Thank you, 1st running this : Install-Package NuGet.CommandLine then the above did the trick for me – Nick G. Dec 25 '17 at 17:46
  • @NickG. That didn't work either. Maybe `Install-Package NuGet` ? – Kellen Stuart Jul 05 '19 at 20:24
  • 2
    'Update-Package -reinstall' helped me. Thanks a lot. – Pankaj Kaushik Jan 24 '22 at 11:48
25

Honestly, whoever developed the NuGet command for VS needs to go back to the drawing board. They totaly missed the fact that sometimes these DLL(s) and/or files get corrupt or deleted. a "NuGet Get-Packages -Force" option would really save their bacon. The only GAP I see is that VS and the Package console does not allow you to invoke a forced download from NuGet. Even clearing the cache via VS is useless.

RashadRivera
  • 793
  • 10
  • 17
12

I ran into this issue when I tried to build my project on a computer where the packages-folder did not already exist in the solution root.

When the project file was initially created, it seems VS2019 added the following into the project file:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>

From what I understand those settings are deprecated nowadays, no idea why VS inserted it in the first place.

Anyway, after removing those lines VS restored the packages and built the solution correctly again.

Anders
  • 734
  • 8
  • 12
2

It's probably a good idea to clear the Nuget Cache by deleting the contents within this directory: C:\Users\{your_username}\AppData\Local\NuGet

Fabio
  • 791
  • 1
  • 7
  • 27
1

All you need is that: Open the Package Manager Console and run this command: Update-Package -reinstall

P.S: VS2017 and above NuGet Package Manager is included with Visual Studio, no need to install anything else.

Coden
  • 2,579
  • 1
  • 18
  • 25
1

The problem with the functionality of the NuGet package can also be caused by the fact that NuGet package is requiring certain dependency that the project does not meet.

NuGet package can have a declared dependency in Dependecies section, e.g. .NETFramework,Version=v.4.6.2 while the project is targeted to an older version (Target framework: .NET Framework 4.6.1.).

Instead of the NuGet system notifying the user of this fact, the project simply does not compile.

tibx
  • 840
  • 13
  • 20
1

In my case, I have different Nuget configurations, and somehow the HintPath in the project file didn't fit.

enter image description here

Maybe you should check if the HintPath leads to the right NuGetPackages folder.

You should also check the following entries at the top of the file: enter image description here

And at the bottom of the file: enter image description here

All these paths should point to the right NuGetPackage folder in your file structure.

troYman
  • 1,648
  • 16
  • 18
1

In my case the problem was solved by deleting the "obj" folder(s) and then rebuilding the solution.

The "obj" folder had several NuGet related files that still referred to version 0.0.2 of a package while all projects in the solution were already using version 1.0.0 of that package. Building the solution failed with the error message "package with version 0.0.2 could not be found". The solution with build folders included was recently copied from another machine.

HyperQuantum
  • 1,532
  • 1
  • 10
  • 12
0

Well it's probably a bad way but I found that it works if I just delete the line

http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />

from the project.csproj , not sure if this is going to cause problems later on but it works for now.

Thijser
  • 2,625
  • 1
  • 36
  • 71