5

Through automatic nuget restore is convenient it is not safe. I previously checked in all packages into the repository. This was easy as VS created a packages directory under the project root.

Now I find I have a

~/.nuget 

directory outside the project hierarchy. Is there a way to revert the behavior? Perhaps a flag in the *.csproj file?

Bugs
  • 4,491
  • 9
  • 32
  • 41
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
  • Possible duplicate of [How do I include NuGet packages in my solution for .Net Core projects?](http://stackoverflow.com/questions/43687058/how-do-i-include-nuget-packages-in-my-solution-for-net-core-projects) – Martin Ullrich May 09 '17 at 11:49
  • Ah sry, it isn't really – Martin Ullrich May 09 '17 at 11:50
  • I'm not aware of NuGet restore being "unsafe", in fact my experience is the opposite - checking in packages can lead to build issues if the package contents are not correctly added (e.g. dlls are excluded). NuGet [caches packages locally](https://learn.microsoft.com/en-us/nuget/consume-packages/managing-the-nuget-cache) so offline restore should work just fine as long as you have download the package once. – Justin May 09 '17 at 12:49
  • 1
    Unsafe in that if I have to rebuild from source in 15 years time to debug a customer installation I don't want to find that the particular version of the nuget package I was relying on has disappeared from the Nuget gallery or that the nuget gallery doesn't exist anymore. Some companies have such support contracts. – bradgonesurfing May 09 '17 at 13:08

1 Answers1

9

You can change the location for the global package folder to a solution-local location by specifying a path in a NuGet.Config file next to the solution (note that you have to re-open the solution for this to have an effect):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value=".\packages" />
  </config>
</configuration>

There are two properties that can be set this way to affect the location of where the packages will be restored to. repositoryPath for packages.config projects and globalPackagesFolder for project.json and projects usingPackageReference.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217