Ilya Chumakov
Ilya Chumakov

Reputation: 25019

Change NuGet package folders used by Visual Studio

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?

Upvotes: 41

Views: 47300

Answers (3)

Ilya Chumakov
Ilya Chumakov

Reputation: 25019

UPD 2024: standalone nuget commands replaced with dotnet nuget CLI. The information provided is relevant for VS2022 and .NET 8.

Cache locations

Solution-local packages folders are no longer used by .NET Core and Visual Studio. The command to list user-specific folders is:

 dotnet nuget locals all --list

And its typical output (I've replaced absolute paths with variables and prettified it):

global-packages:    %USERPROFILE%\.nuget\packages

http-cache:         %$LOCAL_APPDATA%\NuGet\v3-cache
temp:               %$LOCAL_APPDATA%\Temp\NuGetScratch
plugins-cache:      %$LOCAL_APPDATA%\NuGet\plugins-cache

Notice that the machine-wide folder isn't listed there. However, it is defined at Visual Studio settings: Options -> NuGet Package Manager -> Package Sources. By default it is:

C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

In Package Sources, you can add/remove as many cache locations as you want.

Configuration files

NuGet.config files are located here:

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

Any NuGet.config settings can be overriden at many levels (project, solution, user, machine). Read more about NuGet.config hierarchical priority ordering here: How settings are applied.

For example, globalPackagesFolder parameter changes a package cache location:

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

Upvotes: 71

Can
Can

Reputation: 75

Copying the .nuget folder (c:\users{username}.nuget) from the development pc which has an internet connection and the updated packages, to the pc which doesn't have the internet connection also worked for me.

Upvotes: 0

Michael van der Horst
Michael van der Horst

Reputation: 550

From the MS docs:

global‑packages

  • Windows: %userprofile%\.nuget\packages
  • Mac/Linux: ~/.nuget/packages

Override using the NUGET_PACKAGES environment variable, the globalPackagesFolder or repositoryPath configuration settings (when using PackageReference and packages.config, respectively), or the RestorePackagesPath MSBuild property (MSBuild only). The environment variable takes precedence over the configuration setting.

Upvotes: 13

Related Questions