Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change NuGet package folders used by Visual Studio 2017

There is no more packages solution folder in any csproj or project.json-based .NET Core project.

NuGet CLI gets the list of used cache folders:

nuget locals all -list 

Response:

http-cache: C:\Users\<foo>\AppData\Local\NuGet\v3-cache global-packages:  C:\Users\<foo>\.nuget\packages\ temp: C:\Users\<foo>\AppData\Local\Temp\NuGetScratch 

How to change or override these locations?

like image 648
Ilya Chumakov Avatar asked Apr 21 '17 11:04

Ilya Chumakov


People also ask

How do I change NuGet package location?

Open %AppData%\NuGet folder, open existing NuGet. Config file. Edit repositoryPath key and set new destination.

Where is the NuGet Packages folder?

The location of the default global packages folder. The default is %userprofile%\. nuget\packages (Windows) or ~/. nuget/packages (Mac/Linux).

Can I delete C :\ Users NuGet packages?

Yes, the . nuget folder is used as a cache for packages downloaded to speed up project restore and compilation. It can safely be removed.


1 Answers

Cache locations

Solution-local packages folders are no longer exist for .NET Core and Visual Studio 2017.

NuGet is now fully integrated into MSBuild:

Solution-local packages folders are no longer used – Packages are now resolved against the user’s cache at %userdata%.nuget, rather than a solution specific packages folder. This makes PackageReference perform faster and consume less disk space by using a shared folder of packages on your workstation.

NuGet 4.0+ uses at least two global package locations:

  • User-specific: %userprofile%\.nuget\packages\
  • Machine-wide: %ProgramFiles(x86)%\Microsoft SDKs\NuGetPackages\"

You can list all user-specific folders using the following console command:

nuget locals all -list 

Notice that the machine-wide folder isn't listed there. However, it is defined at Visual Studio settings:

Options -> NuGet Package Manager -> Package Sources 

Configuration files

NuGet.config files are located here:

  • User-specific: %APPDATA%\NuGet\
  • Machine-wide: %ProgramFiles(x86)%\NuGet\Config\

It is possible to change and override NuGet settings at many levels:

  • project
  • solution
  • user
  • machine

And even more! Read more about NuGet.config hierarchical priority ordering here: How settings are applied.

For example, globalPackagesFolder parameter changes a package cache location. Look at this NuGet.config example:

<?xml version="1.0" encoding="utf-8"?> <configuration>   <config>     <clear />     <add key="globalPackagesFolder" value="c:\packages" />   </config> </configuration> 
like image 185
Ilya Chumakov Avatar answered Oct 08 '22 21:10

Ilya Chumakov