Thijser
Thijser

Reputation: 2633

NuGet has problems with missing packages, how to restore?

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?

Upvotes: 36

Views: 29267

Answers (10)

Madalitso Nyemba
Madalitso Nyemba

Reputation: 15

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

Upvotes: 1

HyperQuantum
HyperQuantum

Reputation: 1672

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.

Upvotes: 1

troYman
troYman

Reputation: 1808

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.

Upvotes: 2

tibx
tibx

Reputation: 926

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.

Upvotes: 1

Redhwan Ghailan
Redhwan Ghailan

Reputation: 19

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.

Upvotes: 1

Anders
Anders

Reputation: 744

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.

Upvotes: 12

RashadRivera
RashadRivera

Reputation: 843

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.

Upvotes: 26

Thijser
Thijser

Reputation: 2633

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.

Upvotes: 0

Rahul Nikate
Rahul Nikate

Reputation: 6337

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

Upvotes: 30

Fabio
Fabio

Reputation: 791

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

Upvotes: 2

Related Questions