Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discover/Find the physical location of the "packages" directory a Project is actually using for installed Nuget Packages

So I have inherited a project and I just noticed there is a "packages" directory at the solution root and a second "packages" directory inside a project that is part of the solution.

I hope that Nuget is not using a mix of both locations for installed packages and I want to use the solution root level for storing/referencing packages of course.

Is there a way I can find the actual physical location that a project is using for a package other than looking at the F4 properties on each DLL, because this does not help me with Javascript Nuget packages and also, is there a way to change the physical reference without Uninstalling and reinstalling every package?

Update Updating this answer to share what I did so far,even though I have not achieved a solution yet

So I deleted the packages directory in ProjectA and committed to TFS.

I then closed Visual Studio 2012 and made sure that my ProjectA/packages.config remained fully intact, no changes.

I built ProjectA and had reference errors. I then tried running Update-Package -Reinstall and this just physically deleted most of my packages and did not reinstall them.

I checked my Nuget.config, I checked my .csproj I deleted csproj.user and .suo files. I closed Visual Studio 2012 repeatedly. Nothing is giving me a good build again, nothing is restoring my Nuget packages, I have asked a new Question: https://stackoverflow.com/questions/30406566/nuget-is-removing-packages-on-update-package-reinstall-after-moving-packages-di

like image 525
Brian Ogden Avatar asked Mar 16 '23 00:03

Brian Ogden


1 Answers

As you stated, when you create a project that doesn't have a Solution folder, NuGet will create a packages folder in the root of your project. Packages will be installed there and your project will reference assemblies from the project's packages folder.

/ProjectA
   /packages

When you create a solution and move this project into the solution folder, you end up with something like this:

/Solution
   /packages  <= solution packages
   /ProjectA
      /packages  <= packages from original project
   /ProjectB

Once you attempt to build this solution, NuGet will see if there are any missing packages in the solution packages folder (such as those from ProjectA). NuGet Package Restore will then download those missing packages into the solution packages folder.

Also, any new packages you add will always be installed in the solution packages folder. Even if you install a package to ProjectA which had its own packages folder.

At this point, you should remove the packages folder in ProjectA. Unfortunately, this causes a problem. The main issue is that ProjectA still has references to assemblies in its own packages folder. When you remove the packages folder, you are not able to build due to missing references.

Luckily, there is an easy fix for this. Simply open up the Package Manager Console and enter:

Update-Package -Reinstall

This will force NuGet to go through each project and uninstall/reinstall each package. This also ensures that each of the references are now updated to the solution packages folder. NOTE: since the packages were already downloaded, this is a pretty quick process and only needed once to fix-up the references.

like image 182
Kiliman Avatar answered Mar 26 '23 03:03

Kiliman