Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange Nuget error while enabling Nuget package restore

I right click on my solution file in my VS2010 and clicked Enable NuGet Package Restore, and I got an error message saying Unable to read package from path 'NuGet.CommandLine.2.7.1.nupkg'.

I googled around and don't see anything close.

Any clue?

like image 246
hardywang Avatar asked Oct 26 '13 00:10

hardywang


People also ask

How do I fix a NuGet package error?

Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.

How do I force a NuGet package to restore?

Restore NuGet packagesNavigate to Tools > Options > NuGet Package Manager > General, and then select the Allow NuGet to download missing packages check box under Package Restore. Enabling Restore NuGet Packages. In Solution Explorer, right-click the solution, and then select Restore NuGet Packages.

How do I enable NuGet package restore in Visual Studio?

To do that, go to Tools, NuGet Packaged Manager, then go to Package Manager Settings. Go to the General section, and then make sure you have a checkmark for Allow NuGet to download missing packages and also to automatically check for missing packages during the build in Visual Studio. So click on OK.

How do I reinstall NuGet restore?

After you enable package restore in Options, you can right-click the solution in Solution Explorer and select Restore NuGet Packages to restore packages anytime. If you enabled automatic restore in Options, Package Restore happens automatically when you create a project from a template or build a project.


1 Answers

The error message is usually because NuGet cannot open the NuGet package because it failed to download it. I would check your NuGet cache to see if the NuGet.CommandLine.2.7.1.nupkg file is zero bytes or smaller than expected. If so delete the file or clear the cache and try again. Sometimes the download can fail and NuGet leaves an empty file in the cache which causes problems on installing that NuGet package. You can also see the error if the NuGet package did not fully download, so the package will not be zero bytes but will not have fully downloaded and NuGet cannot open it. So it is worth deleting the NuGet package from the cache and retrying.

The NuGet cache is in the following directory:

%localappdata%\NuGet\Cache

You can also browse to the NuGet cache from inside Visual Studio by opening the Package Manager Settings, selecting General and clicking the Browse button.

Note that with newer versions of NuGet 2.8 this problem should be fixed. NuGet in later versions will download to a temporary file location and renamed once the download is completed so a partially download NuGet package will not be left in the cache.

like image 56
Matt Ward Avatar answered Sep 17 '22 22:09

Matt Ward