Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Packages through Nuget - "Central Directory corrupt"

I'm trying to add a package to my project using NuGet (in VS2015). When I click the "Install" button I see

Downloading missing packages...

at the top of the screen with a progress bar.

After a moment the message is replaced with -

An error occurred while trying to restore packages: Central Directory corrupt.

with a "Restore" button at the end which does the same process.

Anyone have any idea how to fix this?

like image 993
John C Avatar asked Jan 11 '16 12:01

John C


People also ask

What directory is the package installed with NuGet?

The global-packages folder is where NuGet installs any downloaded package. Each package is fully expanded into a subfolder that matches the package identifier and version number. Projects using the PackageReference format always use packages directly from this folder.

How do I force a NuGet package to install?

Switch to the Browse tab, search for the package name, select it, then select Install). For all packages, delete the package folder, then run nuget install . For a single package, delete the package folder and use nuget install <id> to reinstall the same one.

How do I fix NuGet recovery failed?

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.

What happens when you install a NuGet package?

NuGet creates a subfolder for each package identifier, then creates subfolders for each installed version of the package. NuGet installs package dependencies as required. This process might update package versions in the process, as described in Dependency Resolution.


2 Answers

Edit 07/2017

A far easier method of solving this issue is be to just get Visual Studio to re-download the package -

  1. In Visual Studio open Tools -> Options.
  2. Select NuGet Package Manager.
  3. Ensure both Allow NuGet to download missing packages and Automatically check for missing packages during build in Visual Studio are both ticked.
  4. Click OK.
  5. In a file explorer window navigate into the projects' "packages" folder.
  6. Three options -
    • Figure out which package is at fault as described in the original answer and delete it's folder.
    • Move all the packages to a temporary location if you're unsure whether they're all still available in NuGet (you'll need to copy the missing ones back afterwards)
    • Delete all the package folders if you are sure all your packages are still available in NuGet.
  7. Back in Visual Studio build your solution.
  8. Visual Studio should download all your packages.

Original Answer

Ok, the problem here was that the .nupkg file for one package (found in project root/packges/package folder) had been corrupted at some point and had a size of zero.

I figured out which package was corrupt after attempting to manually install a random package using the package manager console -

Install-Package *package name*

which told me that there was a problem with a currently installed package -

Install-Package : An error occurred while retrieving package metadata for 'package name'....

From there I was able to fix it by doing the following -

  1. Navigate to the to the NuGet site
  2. Search for the project using the search facility at the top of the page
  3. Download the .nupkg file using the "Download" link on the left hand side (checking the version number).
  4. Copy the downloaded file over the old one in the "packages" folder.
like image 176
John C Avatar answered Sep 17 '22 16:09

John C


Remove all nuget packages under \packages\ ( i had multiple corrupted packages)

Go to your solution in Visual Studio and press "Restore Nuget Packages"

Rebuild your solution

Should be fixed :)

like image 45
NicoJuicy Avatar answered Sep 17 '22 16:09

NicoJuicy