Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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). When trying to install it via Nuget I get the following error when attempting to resolve the dependency. Further I've gotten this error every time (see my troubleshooting later in this question):

Screenshot of Package Manager Console

I've done the following steps in no particular order (multiple times each in various combinations):

  • Run '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
  • Delete the entire project from the physical drive and TFS, and recreate it from scratch (it creates with the references incorrect)
  • Install the package via both the command line and 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

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. 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.

like image 419
Ranger Avatar asked Apr 29 '16 17:04

Ranger


People also ask

How do I fix a missing NuGet package?

Enable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.

Where are NuGet packages stored in project?

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 reinstall?

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.


2 Answers

Close the solution then go to the packages folder on your hard drive and delete all its contents. Open your application again in Visual Studio and it will automatically try to restore the packages. Clean the Solution and Build it.

like image 137
Ifeanyi Nnamdi-Okagbue Avatar answered Sep 19 '22 10:09

Ifeanyi Nnamdi-Okagbue


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

like image 23
Nazım Gediz Aydındoğmuş Avatar answered Sep 22 '22 10:09

Nazım Gediz Aydındoğmuş