36

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?

10 Answers 10

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
18
  • 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, 2016 at 11:20
  • 3
    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. Jun 28, 2016 at 11:31
  • 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, 2017 at 21:01
  • 2
    Thank you, 1st running this : Install-Package NuGet.CommandLine then the above did the trick for me
    – Nick G.
    Dec 25, 2017 at 17:46
  • 2
    'Update-Package -reinstall' helped me. Thanks a lot. Jan 24, 2022 at 11:48
26

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.

5
  • 1
    Too frigging right. One workaround for this is to uninstall the packages form your project then reinstall them. Sucks.
    – Mardoxx
    Sep 13, 2018 at 15:56
  • 14
    It's the year 2020 and this is still broken
    – Rich
    Jan 20, 2020 at 10:11
  • 7
    2022 and counting.
    – Manuzor
    Jan 14, 2022 at 11:40
  • 4
    2023 and counting. Mar 13, 2023 at 20:10
  • 2024. We move..
    – nc404
    Apr 1 at 16:12
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.

1
  • Thanks, this solved it for me. No clue why this reference was placed in my project file. Jul 23, 2020 at 11:56
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

2
  • I tried that but it didn't solve the problem (even after rebooting VS)
    – Thijser
    Jun 28, 2016 at 11:21
  • In my case, I had to clear this directory and C:\Users\{your_username}\.nuget\packages for the issue to be resolved. Feb 21, 2023 at 19:01
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.

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.

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.

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.

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.

0

For me, I tried deleting the bin and obj folders, restarting VS, restarting my PC but to no avail. However, running

dotnet restore

fixed the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.