Skip to content

Commit fc69c5f

Browse files
authored
update page on local directories (#3528)
1 parent 465c286 commit fc69c5f

1 file changed

Lines changed: 32 additions & 34 deletions

File tree

docs/consume-packages/managing-the-global-packages-and-cache-folders.md

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: How to manage the global packages, cache, temp folders in NuGet
3-
description: How to manage the global package installation folder, the package cache, and the temp folders that exist on a computer, which are used when installing, restoring, and updating packages.
4-
author: JonDouglas
5-
ms.author: jodou
6-
ms.date: 03/19/2018
2+
title: How to manage the global packages, HTTP cache, temp folders in NuGet
3+
description: How to manage the global package installation folder, the HTTP cache, and the temp folders that exist on a computer, which are used when installing, restoring, and updating packages.
4+
author: zivkan
5+
ms.author: zivkan
6+
ms.date: 01/30/2026
77
ms.topic: how-to
88
---
99

10-
# Managing the global packages, cache, and temp folders
10+
# Managing the global packages, HTTP cache, and temp folders
1111

1212
Whenever you install, update, or restore a package, NuGet manages packages and package information in several folders outside of your project structure:
1313

@@ -18,12 +18,13 @@ Whenever you install, update, or restore a package, NuGet manages packages and p
1818
| [temp](#temp) | <li>Windows: `%temp%\NuGetScratch`</li><li>Mac: `/tmp/NuGetScratch`</li><li>Linux: `/tmp/NuGetScratch<username>`</li><li>Override using the NUGET_SCRATCH environment variable.</li></ul> |
1919
| [plugins-cache](#plugin-cache) **4.8+** | <ul><li>Windows: `%localappdata%\NuGet\plugins-cache`</li><li>Mac/Linux: `~/.local/share/NuGet/plugins-cache`</li><li>Override using the NUGET_PLUGINS_CACHE_PATH environment variable.</li></ul> |
2020

21-
> [!Note]
22-
> NuGet 3.5 and earlier uses *packages-cache* instead of the *http-cache*, which is located in `%localappdata%\NuGet\Cache`.
21+
By using the *global-packages* folder, NuGet generally avoids downloading packages that already exist on the computer, improving the performance of install, update, and restore operations.
22+
When using PackageReference, the *global-packages* folder also avoids keeping downloaded packages inside project folders, where they might be inadvertently added to source control, and reduces NuGet's overall impact on computer storage.
2323

24-
By using the cache and *global-packages* folders, NuGet generally avoids downloading packages that already exist on the computer, improving the performance of install, update, and restore operations. When using PackageReference, the *global-packages* folder also avoids keeping downloaded packages inside project folders, where they might be inadvertently added to source control, and reduces NuGet's overall impact on computer storage.
25-
26-
When asked to retrieve a package, NuGet first looks in the *global-packages* folder. If the exact version of package is not there, then NuGet checks all non-HTTP package sources. If the package is still not found, NuGet looks for the package in the *http-cache* unless you specify `--no-http-cache` with `dotnet.exe` commands or `-NoHttpCache` with `nuget.exe` commands. If the package is not in the cache, or the cache isn't used, NuGet then retrieves the package over HTTP .
24+
When asked to retrieve a package, NuGet first looks in the *global-packages* folder.
25+
If the exact version of the package is not there, then NuGet checks all non-HTTP package sources.
26+
If the package is still not found, NuGet looks for the package in the *http-cache* unless you specify `--no-http-cache` with `dotnet.exe` commands or `-NoHttpCache` with `nuget.exe` commands.
27+
If the package is not in the HTTP cache, or the HTTP cache isn't used, NuGet then retrieves the package over HTTP.
2728

2829
For more information, see [What happens when a package is installed?](../concepts/package-installation-process.md).
2930

@@ -44,7 +45,7 @@ In Visual Studio, you may need to reload your solution to clear NuGet's "up to d
4445
To clean only unused packages, it's a two step process.
4546
First, there is a [nuget.config setting `updatePackageLastAccessTime`](../reference/nuget-config-file.md) that should be enabled.
4647
This setting will cause NuGet to update each package's `.nupkg.metadata` file when it is used in a restore.
47-
When restore runs, but a project is considered already up to date, the package timestamps are *not* updated.
48+
When restore runs, but a project is considered already up to date, the package timestamps are *not* updated, so if a project's restore inputs don't change for several weeks, the `.nupkg.metadata` files will not have their timestamps updated.
4849
The `.nupkg.metadata` file is the last file that NuGet will create when downloading and extracting packages during a restore or install, and is the file that restore uses to check if a package has been extracted successfully.
4950

5051
Second, run a tool to perform the cleanup.
@@ -57,7 +58,7 @@ Some community members have created their own open source NuGet cleaner tools th
5758
If you are going to write your own cleanup tool, it is important that the `.nupkg.metadata` file is deleted if any of the other package files are deleted, so we recommend that this file is deleted first.
5859
Otherwise projects referencing the package may have unexpected behavior.
5960
If writing a cleanup tool in .NET, consider using `ConcurrencyUtilities.ExecuteWithFileLocked[Async](..)` from the [NuGet.Common package](https://www.nuget.org/packages/NuGet.Common), passing the full nupkg path of the package directory you're going to delete as the key, to avoid deleting a package that restore is trying to extract at the same time.
60-
The global packages directory can be programatically found with the [NuGet.Configuration package](https://www.nuget.org/packages/NuGet.Configuration).
61+
The global packages directory can be programmatically found with the [NuGet.Configuration package](https://www.nuget.org/packages/NuGet.Configuration).
6162
Use `Settings.LoadDefaultSettings(path)` to get an `ISettings` instance (you can pass `null` as the path, or pass a directory if you want to handle solutions with a nuget.config that redirects the global-packages directory), and then use `SettingsUtility.GetGlobalPackagesFolder(settings)`.
6263
Alternatively, you can run `dotnet nuget locals global-packages --list` as a child process and parse the output.
6364

@@ -66,22 +67,29 @@ Alternatively, you can run `dotnet nuget locals global-packages --list` as a chi
6667
NuGet will cache copies of most NuGet feed communications (excluding search), organized into subfolders for each package source.
6768
Packages are not expanded, and files with a last modified date older than 30 minutes are typically considered expired.
6869

70+
PackageReference restore will cache the list of versions a source contains.
71+
So, if a new version of a package is published and you want to use it more quickly than the 30 minute cache expiration period, you can clear the http-cache to force restore to check for a newer version more quickly.
72+
6973
## temp
7074

7175
A folder where NuGet may store temporary files during its various operations.
7276

77+
If multiple NuGet operations are performed in parallel, for example a single machine running multiple CI agents, it's important for all of the processes to share the same temp (`NuGetScratch`) directory.
78+
NuGet uses the temp directory to coordinate inter-process access to the http-cache and global-packages directories, using filesystem locks.
79+
If different processes use different temp directories, but the same global-packages or http-cache directory, various errors might occur when trying to restore or install packages.
80+
NuGet does not use filesystem locking to coordinate restoring projects, so two different processes trying to restore the same project at the same time can encounter problems even when using the same `NuGetScratch` directory.
81+
7382
## plugin-cache
7483

7584
A folder where NuGet stores the results from the operation claims request.
7685
See the [cross platform plugins reference](../reference/extensibility/NuGet-Cross-Platform-Plugins.md) for more information.
7786

7887
## Viewing folder locations
7988

80-
You can view locations using the [nuget locals command](../reference/cli-reference/cli-ref-locals.md):
89+
You can view directory locations using the [dotnet nuget locals command](/dotnet/core/tools/dotnet-nuget-locals):
8190

8291
```cli
83-
# Display locals for all folders: global-packages, http cache, temp and plugins cache
84-
nuget locals all -list
92+
dotnet nuget locals all --list
8593
```
8694

8795
Typical output (Windows; "user1" is the current username):
@@ -93,14 +101,6 @@ temp: C:\Users\user1\AppData\Local\Temp\NuGetScratch
93101
plugins-cache: C:\Users\user1\AppData\Local\NuGet\plugins-cache
94102
```
95103

96-
(`package-cache` is used in NuGet 2.x and appears with NuGet 3.5 and earlier.)
97-
98-
You can also view folder locations using the [dotnet nuget locals command](/dotnet/core/tools/dotnet-nuget-locals):
99-
100-
```dotnetcli
101-
dotnet nuget locals all --list
102-
```
103-
104104
Typical output (Mac; "user1" is the current username):
105105

106106
```output
@@ -121,20 +121,24 @@ info : plugins-cache: /home/user1/.local/share/NuGet/plugins-cache
121121

122122
To display the location of a single folder, use `http-cache`, `global-packages`, `temp`, or `plugins-cache` instead of `all`.
123123

124+
You can also view locations with NuGet.exe with [the locals command](../reference/cli-reference/cli-ref-locals.md):
125+
126+
```cli
127+
# Display locals for all directories: global-packages, http-cache, temp and plugins-cache
128+
nuget locals all -list
129+
```
130+
124131
## Clearing local folders
125132

126133
### Command-line
127134

128135
If you encounter package installation problems or otherwise want to ensure that you're installing packages from a remote gallery, use the `locals --clear` option (dotnet.exe) or `locals -clear` (nuget.exe), specifying the folder to clear, or `all` to clear all folders:
129136

130137
```cli
131-
# Clear the 3.x+ cache (use either command)
138+
# Clear the HTTP cache (use either command)
132139
dotnet nuget locals http-cache --clear
133140
nuget locals http-cache -clear
134141
135-
# Clear the 2.x cache (NuGet CLI 3.5 and earlier only)
136-
nuget locals packages-cache -clear
137-
138142
# Clear the global packages folder (use either command)
139143
dotnet nuget locals global-packages --clear
140144
nuget locals global-packages -clear
@@ -152,8 +156,6 @@ dotnet nuget locals all --clear
152156
nuget locals all -clear
153157
```
154158

155-
Any packages used by projects that are currently open in Visual Studio are not cleared from the *global-packages* folder.
156-
157159
### Visual Studio
158160

159161
Visual Studio supports clearing all local folders in the "NuGet Package Manager" options found under the **Tools > NuGet Package Manager > Package Manager Settings** menu command.
@@ -164,12 +166,8 @@ A progress bar will be shown and will contain the final status of the command.
164166

165167
The [Output Window](/visualstudio/ide/output-window) when selecting Show output from "Package Manager" will show additional details about the clear command, including any error messages.
166168

167-
### Clear NuGet Local Resources
168-
169169
![Clear NuGet local resources button highlighted in the General page of NuGet options](media/vsoptions/general.png)
170170

171-
Managing the cache isn't presently available through the Package Manager Console.
172-
173171
For more information, see [NuGet Options in Visual Studio](nuget-visual-studio-options.md#clear-nuget-local-resources).
174172

175173
## Troubleshooting errors

0 commit comments

Comments
 (0)