9

I understand that it is now possible to configure a global package directory for all projects but I noticed that NuGet also puts files in my home directory. Is it possible to configure a single repo which will be used for all projects?

Shane
  • 2,271
  • 3
  • 27
  • 55

2 Answers2

8

NuGet introduced a new way of package management in for project.json (now deprecated) and PackageReference-based projects (default .NET Core, .NET Standard).

Instead of creating a solution-local packages folder to which all packages are downloaded and extracted (alt: repositoryPath location in NuGet.Config override), all packages are downloaded to a global location (controlled by globalPackagesFolder in NuGet.Config) which is defaulted to %userprofile%\.nuget\packages (~/.nuget/packages on linux/Mac).

The idea is that you don't have to download packages multiple times and the csproj files no longer reference all individual files but just the package. .NET Core projects also do not need to copy the NuGet packages' assets because the generated .runtimeconfig.json file specifies the location of the global cache to look up the packages at runtime, so builds can be a little bit faster.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • Thanks very much for your answer, things are a bit clear now. I found some info on project.json here: https://github.com/NuGet/Home/wiki/Converting-a-csproj-from-package.config-to-project.json. I am still on on Visual Studio 2015, does that mean I need to use project.json util I can upgrade to 2017? Also is there away to configure dependencies using the package manager console I do I have edit project.json by hand? – Shane Sep 06 '17 at 06:03
  • Yes 2015 only has classic `packages.config` or `project.json`. I think the package manger console has support for project.json, but the intent is to be able to edit the file (or the simplified csproj file in 2017) manually as well (e.g. when not using VS) – Martin Ullrich Sep 06 '17 at 06:31
  • this does not play well with source control integration. VS2017 and VS2019 always complain that this user profile folder is not mapped in the workspace. mapping it is not an option in our scenario) – Cee McSharpface Mar 11 '21 at 14:51
-2

See this question, I believe everything will be clear after that

Setting up a common nuget packages folder for all solutions when some projects are included in multiple solutions

Mike
  • 24
  • 4
  • This is about `repositoryPath`, not the new global package cache – Martin Ullrich Sep 05 '17 at 10:36
  • Thanks but have read this question which helped me figure out how to specify a central local for project to reference packages from but it doesn't explain why I have packages in my user directory which don't seem to be referenced anywhere. – Shane Sep 05 '17 at 11:38
  • This makes it a bit clearer https://learn.microsoft.com/en-us/nuget/consume-packages/managing-the-nuget-cache - it seems there is just one but several caches. – Shane Sep 05 '17 at 12:29
  • It's the `globalPackagesFolder` which is used for new-style csproj projects (and has been used for `project.json` in VS 2015 / UWP projects) – Martin Ullrich Sep 05 '17 at 13:40