NuGet has problems with missing packages, how to restore?
Asked Answered
F

10

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?

Funkhouser answered 28/6, 2016 at 11:9 Comment(0)
P
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
Pickax answered 28/6, 2016 at 11:15 Comment(18)
nuget restore TestEnvi.sln give me the error The term 'restore' is not recognized as the name of a cmdlet, function, scriptFunkhouser
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''Funkhouser
Did you try Update-Package -reinstall command in package manager consolePickax
That runs for a bit and then throws the error ' The item 'packages.config' cannot be deleted 'Funkhouser
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.Pickax
Hmm running it a second time it did complete, but I still canot run the restore command (nuget not recognized) and the problem persitsts.Funkhouser
Try deleting whole packages folder from solution and then run Update-Package -reinstallPickax
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 questionFunkhouser
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 nugetPickax
Any advice how to deal with these? The file sits on an veracrypt encrypted file so shouldn' t that sort of auto detect problems?Funkhouser
You need to check your OS and computer system. It has nothing to do with nuget. sorry its out of my knowledge.Pickax
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.Funkhouser
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.Funkhouser
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."Milker
This worked partly, I also had to add references manually, it was a mix of all the stepsDenary
Thank you, 1st running this : Install-Package NuGet.CommandLine then the above did the trick for meRichardo
@NickG. That didn't work either. Maybe Install-Package NuGet ?Fretwell
'Update-Package -reinstall' helped me. Thanks a lot.Corsage
M
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.

Montemayor answered 24/8, 2017 at 2:32 Comment(5)
Too frigging right. One workaround for this is to uninstall the packages form your project then reinstall them. Sucks.Fosse
It's the year 2020 and this is still brokenPerception
2022 and counting.Eolanda
2023 and counting.Torbart
2024. We move..Subtype
L
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.

Latonia answered 14/2, 2020 at 13:2 Comment(1)
Thanks, this solved it for me. No clue why this reference was placed in my project file.Cletus
M
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

Metabolize answered 28/6, 2016 at 11:15 Comment(2)
I tried that but it didn't solve the problem (even after rebooting VS)Funkhouser
In my case, I had to clear this directory and C:\Users\{your_username}\.nuget\packages for the issue to be resolved.Clytemnestra
E
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.

Eaglestone answered 6/4, 2021 at 11:13 Comment(0)
A
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.

Anatol answered 13/4, 2021 at 20:12 Comment(0)
L
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.

Lanceted answered 10/5, 2021 at 11:32 Comment(0)
C
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.

Creodont answered 3/9, 2021 at 10:57 Comment(0)
F
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.

Funkhouser answered 28/6, 2016 at 12:2 Comment(0)
M
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

Multiplication answered 28/3, 2024 at 16:3 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.