47

I am trying to work around NuGet's source control limitations.

To that end I need to know a bit more about how NuGet works. Let’s take a simple example. Say I have a project and I add AutoMapper to it. When I add it, where is the DLL file supposed to be put?

I ask because it does not seem to be consistent. Sometimes the reference is looking for the DLL file the "Packages" folder:

NuGet using packages path

And sometimes it is looking in the Debug build output folder:

NuGet using the 'Debug' path

But in both cases the AutoMapper line in the packages.config file is the same:

First example:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AutoMapper" version="1.1.0.118" />
  <package id="CommonServiceLocator" version="1.0" />
  <package id="Unity" version="2.1.505.0" />
</packages>

Second example:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="NSubstitute" version="1.1.0.0" />
  <package id="AutoMapper" version="1.1.0.118" />
  <package id="CommonServiceLocator" version="1.0" />
  <package id="Unity" version="2.1.505.0" />
</packages>

So what is controlling where it sets up up the reference to? And how do I make it just use the Packages Location?

(When it uses the Debug output folder those references fail if you to compile for "Release".)

Frustrated Note: I have to admit that I am finding NuGet to be a cool idea, but it is not ready for anything but simple situations. (I am thinking about just going back to having a library folder with all my DLL files in it.)

I can't help but wonder if I am missing something because NuGet has such wide spread adoption. There must be some way to make this work...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Vaccano
  • 78,325
  • 149
  • 468
  • 850
  • What kind of projects are the two? What level are you adding the reference at (project vs. solution)? Did you add the package with Nuget.exe or with Package-Manager console or with UI? **EDIT**: I just tried with those packages and both times it went to the packages folder. Strange. What version of Nuget are you using? – anthony sottile Aug 10 '11 at 23:13
  • The "package one" is a unit test project. The "debug one" is just a class library. Both projects are two and three folder levels deep respectively. I downloaded my NuGet.exe two weeks ago. So it would have to be fairly recent. – Vaccano Aug 10 '11 at 23:48
  • If you're using Nuget.exe what commands are you running to install the packages? Whenever I've used the command line I've usually explicitly stated where I want the files to go. Using the package manager UI or the package manager console I can't seem to reproduce your problem :( – anthony sottile Aug 11 '11 at 00:00

3 Answers3

68

.NET Core

In .NET Core, NuGet packages are now stored in a global location, by default:

Windows: %userprofile%\.nuget\packages

(aka C:\Users\[User]\.nuget\packages)

Linux: ~/.nuget/packages

Additionally, the packages.config was removed with references now being stored using the <PackageReference> element in the .csproj file.

You can find out more documentation here.


If you can't find the global location, it may have been changed. You can discover it using this command:

dotnet nuget locals global-packages --list

If you would like to change the package location to, for example, e:\packages, you can use the following command.

dotnet nuget config -Set globalPackagesFolder=e:\packages

Any problems installing NuGet packages that I've had have always been fixed by clearing all the cache locations (there are additional places where NuGet packages are saved aside from the global location) like so:

dotnet nuget locals all --clear
Hazza
  • 6,441
  • 3
  • 24
  • 37
25

The short answer is that if you install a NuGet package from Visual Studio (either using PowerShell or the dialog), any assemblies that it contains will be referenced from the Packages folder.

Note that Visual Studio has some quirky behavior such that if you try to build and the packages folder is missing, and the DLL file exists in the 'bin' folder, then it switches the reference to go to the 'bin' folder. Maybe that's what you are seeing?

If that's not the case, and you have a reproducible set of steps that lead to assemblies being referenced not from the Packages folder, please open a bug on http://nuget.codeplex.com/.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • 1
    Thank you for your answer! Once I knew how it was supposed to be I was able to fix this. Turns out I had some read only flags set that confused NuGet. Once I fixed those and then deleted the reference and removed the package from the Packages.Config file and then installed again it referenced the right (packages) location. On a side note, it would be nice if there was an "Unintstall" button in the gui instead of just a green check mark. – Vaccano Aug 11 '11 at 14:05
  • 1
    @Vaccano: If you go to the "installed" tab (on the left) there is an uninstall button for each one – anthony sottile Aug 12 '11 at 00:00
  • @Anthony Sottile - Well I feel silly! Thanks for pointing that out to me, it had been really bugging me to remove them manually! – Vaccano Aug 12 '11 at 14:36
  • It is time for an update - *"WE MOVED to github.com/nuget. This site is not monitored!"*. – Peter Mortensen Jul 27 '20 at 19:46
2

This helps me with this issue

  1. Delete the below line in the packages.config file

     < package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net45" />
    
  2. Delete folder "Area" - all the files in it

  3. Install the NuGet package:

     Install-Package Microsoft.AspNet.WebApi.HelpPage
    
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131