You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/consume-packages/managing-the-global-packages-and-cache-folders.md
+32-34Lines changed: 32 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
---
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
7
7
ms.topic: how-to
8
8
---
9
9
10
-
# Managing the global packages, cache, and temp folders
10
+
# Managing the global packages, HTTP cache, and temp folders
11
11
12
12
Whenever you install, update, or restore a package, NuGet manages packages and package information in several folders outside of your project structure:
13
13
@@ -18,12 +18,13 @@ Whenever you install, update, or restore a package, NuGet manages packages and p
18
18
|[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> |
19
19
|[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> |
20
20
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.
23
23
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.
27
28
28
29
For more information, see [What happens when a package is installed?](../concepts/package-installation-process.md).
29
30
@@ -44,7 +45,7 @@ In Visual Studio, you may need to reload your solution to clear NuGet's "up to d
44
45
To clean only unused packages, it's a two step process.
45
46
First, there is a [nuget.config setting `updatePackageLastAccessTime`](../reference/nuget-config-file.md) that should be enabled.
46
47
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.
48
49
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.
49
50
50
51
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
57
58
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.
58
59
Otherwise projects referencing the package may have unexpected behavior.
59
60
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).
61
62
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)`.
62
63
Alternatively, you can run `dotnet nuget locals global-packages --list` as a child process and parse the output.
63
64
@@ -66,22 +67,29 @@ Alternatively, you can run `dotnet nuget locals global-packages --list` as a chi
66
67
NuGet will cache copies of most NuGet feed communications (excluding search), organized into subfolders for each package source.
67
68
Packages are not expanded, and files with a last modified date older than 30 minutes are typically considered expired.
68
69
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
+
69
73
## temp
70
74
71
75
A folder where NuGet may store temporary files during its various operations.
72
76
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
+
73
82
## plugin-cache
74
83
75
84
A folder where NuGet stores the results from the operation claims request.
76
85
See the [cross platform plugins reference](../reference/extensibility/NuGet-Cross-Platform-Plugins.md) for more information.
77
86
78
87
## Viewing folder locations
79
88
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):
81
90
82
91
```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
85
93
```
86
94
87
95
Typical output (Windows; "user1" is the current username):
(`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
-
104
104
Typical output (Mac; "user1" is the current username):
105
105
106
106
```output
@@ -121,20 +121,24 @@ info : plugins-cache: /home/user1/.local/share/NuGet/plugins-cache
121
121
122
122
To display the location of a single folder, use `http-cache`, `global-packages`, `temp`, or `plugins-cache` instead of `all`.
123
123
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
+
124
131
## Clearing local folders
125
132
126
133
### Command-line
127
134
128
135
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:
129
136
130
137
```cli
131
-
# Clear the 3.x+ cache (use either command)
138
+
# Clear the HTTP cache (use either command)
132
139
dotnet nuget locals http-cache --clear
133
140
nuget locals http-cache -clear
134
141
135
-
# Clear the 2.x cache (NuGet CLI 3.5 and earlier only)
136
-
nuget locals packages-cache -clear
137
-
138
142
# Clear the global packages folder (use either command)
139
143
dotnet nuget locals global-packages --clear
140
144
nuget locals global-packages -clear
@@ -152,8 +156,6 @@ dotnet nuget locals all --clear
152
156
nuget locals all -clear
153
157
```
154
158
155
-
Any packages used by projects that are currently open in Visual Studio are not cleared from the *global-packages* folder.
156
-
157
159
### Visual Studio
158
160
159
161
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.
164
166
165
167
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.
166
168
167
-
### Clear NuGet Local Resources
168
-
169
169

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