Clearing NuGet Caches
Tags: tools, cli, devops, dotnet
Published: 2022-01-08 15:08:49

---
title: Clearing NuGet Caches
published: true
date: 2021-07-06 00:29:11 UTC
tags: Tools,cli,DevOps,dotnet
canonical_url: https://chrislayers.com/2021/07/05/clearing-nuget-caches/
---

## What is NuGet?

![NuGet](https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/media/nuget/nuget-logo.png "NuGet")

NuGet is an essential packaging tool used in the .NET ecosystem. NuGet is how packages for .NET are created, hosted, and consumed, along with the tools for each of those roles. For many, NuGet is used through Visual Studio to install and manage packages.  
The dotnet CLI also provides functionality for adding packages, updating packages, and creating packages.

NuGet has changed over the years, originally downloading packages into a project folder where they could be checked in. Today, we don’t typically check packages into our source control. This is where caching comes in.

## NuGet Caches

NuGet manages several folders outside of your project structure when installing, updating, or restoring packages. The locations of the folders vary by platform but the use case is the same. Microsoft has a detailed document on the caches: [Managing the Global Packages and Cache Folders](https://docs.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders).

| Name | Description |
| --- | --- |
| global‑packages | This is where NuGet installs any downloaded package. |
| http‑cache | The Visual Studio Package Manager (NuGet 3.x+) and the dotnet tool store copies of downloaded packages in this cache (saved as .dat files), organized into subfolders for each package source. |
| temp | A folder where NuGet stores temporary files during its various operations. |
| plugins-cache | A folder where NuGet stores the results from the operation claims request. |

## Why do we want to Clear the Caches?

There are a few reasons you might want to clear caches.

- Maybe you’re seeing strange behavior in your builds. I’ve cleared all my caches to make sure I’m downloading the same versions as the build agent
- Upgrading versions of .NET. I’ve had errors (and warnings) from restoring packages into a new version of .NET that were restored in previous versions.

## Clearing Caches

To clear the caches, you can pick the method that works best for you.

In Visual Studio 2019, there is a button in the NuGet section of the options dialog (Tools->Options): ![Options Dialog](https://chrislayers.files.wordpress.com/2021/07/2021-07-05.png "Options")

Using the dotnet CLI, the command is:

`dotnet nuget locals all --clear`

Using the NuGet CLI, the command is:

`nuget locals all -clear`

![Command Line Output](https://chrislayers.files.wordpress.com/2021/07/screenshot-2021-07-05-202713.png "Command output")

### Installing NuGet.exe

NuGet.exe is not installed by default. Visual Studio, Dotnet CLI, and MSBuild have their own mechanism to add, remove, and update NuGet packages.  
The NuGet.exe doesn’t have an installer, and the instructions on website usually involve downloading the exe and adding it to your path. I’ve got a script that downloads it and adds it to your path, you can find it here: [Nuget-Install.ps1](https://gist.github.com/Codebytes/1ae354e736c88adef5b6f802597e3101)