简体   繁体   English

Nuget Package ...在项目中不存在...包...已经存在于文件夹中

[英]Nuget Package … does not exist in project … Package … Already exists in folder

I've been fighting with this error for several hours and can't come up with a solution that works. 我一直在与这个错误斗争几个小时,无法找到一个有效的解决方案。

I have an ASP.Net API within a multi-project solution which has its references/dependencies improperly configured and I've been trying to fix it for two days. 我在一个多项目解决方案中有一个ASP.Net API,它的参考/依赖项配置不正确,我一直试图修复它两天。

The issue is ( I believe ) that the API is missing System.Web.Http / System.Web.Http.WebHost which apparently is included with Microsoft.AspNet.WebApi.Core (per multiple other Stack Overflow questions). 问题是( 我相信 )API缺少System.Web.Http / System.Web.Http.WebHost,它显然包含在Microsoft.AspNet.WebApi.Core中(每多个其他Stack Overflow问题)。 When trying to install it via Nuget I get the following error when attempting to resolve the dependency. 当试图通过Nuget安装它时,我尝试解决依赖关系时收到以下错误。 Further I've gotten this error every time (see my troubleshooting later in this question): 此外,我每次都遇到此错误(请参阅本问题后面的疑难解答):

Package Manager控制台的屏幕截图

I've done the following steps in no particular order (multiple times each in various combinations): 我没有按特定顺序完成以下步骤(各种组合多次):

  • Run 'Update-package Microsoft.AspNet.WebApi.Core -reinstall' 运行'Update-package Microsoft.AspNet.WebApi.Core -reinstall'
  • Delete the solution-wide "Packages" folder and delete the project's packages.config and attempt to restore packages 删除解决方案范围的“Packages”文件夹并删除项目的packages.config并尝试还原包
  • Delete the entire project from the physical drive and TFS, and recreate it from scratch (it creates with the references incorrect) 从物理驱动器和TFS中删除整个项目,并从头开始重新创建它(它创建时引用不正确)
  • Install the package via both the command line and Nuget GUI 通过命令行和Nuget GUI安装软件包
  • Check the solution out to different locations on my hard drive in an attempt to start as fresh as possible 检查解决方案到我硬盘上的不同位置,尝试尽可能新鲜
  • Reboot my computer/Restart Visual Studio 重新启动计算机/重新启动Visual Studio

At this point I'm fine with a non-clean fix, as long as it fixes it. 在这一点上,只要修复它,我就可以使用非干净的修复程序。 The API was working at one point, but then I checked it into TFS, created a branch, and am now working on the branch. API在某一点上工作,但后来我将其检入TFS,创建了一个分支,现在正在分支机构工作。 Possibly some dependencies weren't included (?) but even if this was the case it seems like the steps I've taken should resolve the issue. 可能有一些依赖项没有被包括在内(?)但是即使是这种情况,似乎我采取的步骤应该可以解决问题。

Close the solution then go to the packages folder on your hard drive and delete all its contents. 关闭解决方案,然后转到硬盘驱动器上的packages文件夹并删除其所有内容。 Open your application again in Visual Studio and it will automatically try to restore the packages. 在Visual Studio中再次打开您的应用程序,它将自动尝试还原包。 Clean the Solution and Build it. 清理解决方案并构建它。

Clearing the cache solved the problem for me. 清除缓存为我解决了问题。 There's an option to clear the cache on Tools > Options > NuGet Package Manager > General menu, called Clear All NuGet Cache(s) . 可以选择清除工具>选项> NuGet包管理器>常规菜单中的缓存 ,称为清除所有NuGet缓存

First, uninstall via package manager console the specific NuGet package 首先,通过包管理器控制台卸载特定的NuGet包

Then, please unload the project where this nugget package was referenced for by right click -> Unload Project. 然后,请右键单击 - >卸载项目,卸载引用此nugget包的项目。

After unloading right click in the project and select "Edit {Project Name}.csproj" 卸载后右键单击项目并选择“编辑{项目名称} .csproj”

Find the NuGet package entry within the XML where you previously uninstalled and delete it. 在先前卸载的XML中找到NuGet包条目并将其删除。

Install again the package from package manager console... 从包管理器控制台再次安装包...

None of the other answers worked for me. 没有其他答案对我有用。 It kept going in an endless loop of install, revert, restart VS, never making any progress. 它一直在无限循环的安装,恢复,重启VS,从未取得任何进展。

What I ended up having to do was: 我最终要做的是:

  1. Close VS. 关闭VS.
  2. Delete the offending packages from the packages folder. 从packages文件夹中删除有问题的包。
  3. Edit the packages.config file manually, adding the package names and versions I needed to install. 手动编辑packages.config文件,添加我需要安装的软件包名称和版本。
  4. When I opened the solution again, I right-clicked the project and said "manage NuGet packages" and clicked the "Restore" button that appeared on the banner. 当我再次打开解决方案时,我右键单击该项目并说“管理NuGet包”并单击横幅上显示的“恢复”按钮。 This installed the packages that refused to install. 这安装了拒绝安装的软件包。

For crying out loud! 大声喊叫! Microsoft needs to take a lesson from yarn on how to do package management properly. 微软需要从纱线上吸取教训,了解如何正确地进行包管理。

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

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