17

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?

4 Answers 4

22

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.
4
  • I just had this exact issue as well. Your solution worked, so thanks! Any idea what causes it?
    – Zero3
    Mar 10, 2016 at 13:34
  • @Zero3 no idea I'm afraid. Not long before I found the issue I think I'd been having trouble with my git repository which the project was in but I don't think it was related.
    – John C
    Mar 10, 2016 at 13:50
  • Me too. Had some weird issues switching branches in Git through Visual Studio 2015, and had to force it with TortoiseGit by reverting all local changes. Might be related...
    – Zero3
    Mar 11, 2016 at 10:47
  • Facing the same issue, and resolve it by the solution
    – Mahesh S
    Nov 1, 2019 at 7:38
4

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 :)

1
  • "Error occurred while restoring NuGet packages: End of Central Directory record could not be found."
    – rollsch
    Apr 24, 2019 at 4:48
1

1.First of all read the error.

2.Find the Directory listed on error console. 1.File Explorer ==>>

For Example, My Path is. C:\Code\Ex_Nikesh\20\packages In Packages Find Microsoft.SqlServer.Types.xx.xxx.xx.xx(xx indicates version number)

3.Inside the folder find Microsoft.SqlServer.Types.xx.xxx.xx.xx.nu(Nuget Package File [In My case file size is 0 KB]) Delete that File.

4.Now Download the File and Paste inside Microsoft.SqlServer.Types.xx.xxx.xx.xx Folder Click Here for Download Nuget File

1

My problem was a corrupted zip file in the following folder: C:\Program Files (x86)\Microsoft SDKs\NuGetPackages

I cleared all these packages (offline repository)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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