简体   繁体   English

通过 Nuget 安装包 - “中央目录损坏”

[英]Installing Packages through Nuget - "Central Directory corrupt"

I'm trying to add a package to my project using NuGet (in VS2015).我正在尝试使用 NuGet(在 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?任何人都知道如何解决这个问题?

Edit 07/2017编辑 07/2017

A far easier method of solving this issue is be to just get Visual Studio to re-download the package -解决此问题的一种更简单的方法是让 Visual Studio 重新下载包 -

  1. In Visual Studio open Tools -> Options .在 Visual Studio 中打开Tools -> Options
  2. Select NuGet Package Manager .选择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.确保同时选中Allow NuGet to download missing packagesAutomatically check for missing packages during build in Visual Studio
  4. Click OK .单击OK
  5. In a file explorer window navigate into the projects' "packages" folder.在文件资源管理器窗口中导航到项目的“packages”文件夹。
  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)如果您不确定它们在 NuGet 中是否仍然可用,请将所有包移动到一个临时位置(之后您需要将丢失的包复制回来)
    • Delete all the package folders if you are sure all your packages are still available in NuGet.如果您确定所有包在 NuGet 中仍然可用,请删除所有包文件夹。
  7. Back in Visual Studio build your solution.返回 Visual Studio 构建您的解决方案。
  8. Visual Studio should download all your packages. Visual Studio 应下载所有包。

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.好的,这里的问题是一个包的.nupkg文件(在项目根/packges/包文件夹中找到)在某个时候已损坏并且大小为零。

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导航到 NuGet站点
  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).使用左侧的“下载”链接下载.nupkg文件(检查版本号)。
  4. Copy the downloaded file over the old one in the "packages" folder.将下载的文件复制到“packages”文件夹中的旧文件上。

Remove all nuget packages under \packages\ ( i had multiple corrupted packages)删除 \packages\ 下的所有 nuget 包(我有多个损坏的包)

Go to your solution in Visual Studio and press "Restore Nuget Packages"在 Visual Studio 中转到您的解决方案,然后按“恢复 Nuget 包”

Rebuild your solution重建您的解决方案

Should be fixed:)应该修复:)

1.First of all read the error. 1.首先阅读错误。

2.Find the Directory listed on error console. 2.找到错误控制台上列出的目录。 1.File Explorer ==>> 1.文件资源管理器==>>

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) C:\Code\Ex_Nikesh\20\packages在Packages中找到Microsoft.SqlServer.Types.xx.xxx.xx.xx (xx表示版本号)

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. 3.在文件夹中找到Microsoft.SqlServer.Types.xx.xxx.xx.xx.nu (Nuget 包文件 [在我的情况下文件大小为 0 KB])删除该文件。

4. Now Download the File and Paste inside Microsoft.SqlServer.Types.xx.xxx.xx.xx Folder Click Here for Download Nuget File 4.现在下载文件并粘贴到 Microsoft.SqlServer.Types.xx.xxx.xx.xx 文件夹中 点击这里下载 Nuget 文件

My problem was a corrupted zip file in the following folder: C:\Program Files (x86)\Microsoft SDKs\NuGetPackages我的问题是以下文件夹中的损坏 zip 文件:C:\Program Files (x86)\Microsoft SDKs\NuGetPackages

I cleared all these packages (offline repository)我清除了所有这些包(离线存储库)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM