Skip to main content
  1. Posts/

Clearing NuGet Caches

·680 words·4 mins
Chris Ayers
Author
Chris Ayers
I am a father, nerd, gamer, and speaker.

What is 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.

NameDescription
global‑packagesThis is where NuGet installs any downloaded package.
http‑cacheThe 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.
tempA folder where NuGet stores temporary files during its various operations.
plugins-cacheA folder where NuGet stores the results from the operation claims request.

Viewing the cache locations can be done with the dotnet CLI or the nuget cli:

# Display locals for all folders: global-packages, http cache, temp and plugins cache
dotnet nuget locals all --list
nuget locals all -list
http-cache: C:\Users\user1\AppData\Local\NuGet\v3-cache
global-packages: C:\Users\user1\.nuget\packages\
temp: C:\Users\user1\AppData\Local\Temp\NuGetScratch
plugins-cache: C:\Users\user1\AppData\Local\NuGet\plugins-cache

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 2017 and beyond, there is a button in the NuGet section of the options dialog (Tools->Options):

Using the dotnet or nuget CLI, you can clear specific caches or all caches. The commands are:

# Clear the 3.x+ cache (use either command)
dotnet nuget locals http-cache --clear
nuget locals http-cache -clear

# Clear the 2.x cache (NuGet CLI 3.5 and earlier only)
nuget locals packages-cache -clear

# Clear the global packages folder (use either command)
dotnet nuget locals global-packages --clear
nuget locals global-packages -clear

# Clear the temporary cache (use either command)
dotnet nuget locals temp --clear
nuget locals temp -clear

# Clear the plugins cache (use either command)
dotnet nuget locals plugins-cache --clear
nuget locals plugins-cache -clear

# Clear all caches (use either command)
dotnet nuget locals all --clear
nuget locals all -clear

Installing NuGet.exe
#

NuGet.exe is not installed by default on Windows. Visual Studio 2017 and above include nuget package manager functionality via the NuGet Package Manager (GUI and console), but not nuget.exe.

If you install newer versions of the DotNet CLI, it does include dotnet nuget funcationality but not nuget.exe.

The NuGet.exe doesn’t have an installer, and the instructions on the site usually involve downloading the exe and adding it to your path.

There are other ways to install NuGet.exe.

  • winget install Microsoft.NuGet
  • choco install nuget.commandline
  • I’ve got a script that downloads it and adds it to your path, you can find it here: Nuget-Install.ps1

Conclusion
#

In conclusion, understanding and managing NuGet caches is essential for maintaining a healthy development environment, especially when dealing with build issues or upgrading .NET versions. Clearing caches can help resolve strange behavior in your builds and ensure consistency with build agents. With the methods outlined in this post, you can easily clear specific or all caches using Visual Studio, the dotnet CLI, or the nuget CLI. By mastering these cache management techniques, you’ll be well-equipped to tackle any cache-related challenges that come your way, ultimately contributing to a more efficient and reliable development process.

Related

DevOps - The Stakeholders

·385 words·2 mins
When I talk about DevOps, I usually don’t focus on the things like pipelines or automation. While these topics and activities can be part of DevOps, there is so much more to it. I’m sure this will be a multipart blog series so lets get started. The Definition # Let’s make sure we are all on the same page. The definition of DevOps that I love and subscribe to was coined by Donovan Brown at Microsoft.

Shared Focus - Using The First Way with DevOps

·366 words·2 mins
A common issue I see when discussing DevOps with teams or organizations is the presence of Organizational Silos. Organizational Silos are made up of all types of people. Sometimes its a job type, like developers, qa, or infrastructure. Sometimes its a department, like accounting, or hr. Whatever the composition of these silos, they usually impact organizational performance and the ability to deliver value to end users. This happens over time, with members of the silo identifying with each other, viewing those not in the silos as outsiders. Depending on the business, the silos can lose trust in the business overall and tighten ranks around their silo. The silos can turn into walled fortresses. When the silos get in the way, the silos are more focused on their own success than the success of the organization.

How Do You Boil the Ocean?

·329 words·2 mins
This is a phrase I end up using a lot while talking with clients. I used to use a different phrase about elephants but moved away from that language to be more respectful. Let’s start with what it means, at least in the context I use it, and why this phrase is so useful when talking about Devops. The Meaning # I’ve seen and heard a few meanings and usages of the phrase, “Boil(ing) the Ocean”. I’ve heard many negative contexts like: to undertake an impossible task or project. I usually use it in this context, Here is a big task with lots to do, how do you get started and make progress?

Snake Oil DevOps - BEWARE!

·442 words·3 mins
As a DevOps Consultant a lot of what I do is spent on People and Processes. If you remember the definition of DevOps that I love is from Donovan Brown, “DevOps is the union of People, Processes, and Products to continuously deliver value to our end users”. I want to keep reiterating this, continuously deliver value to our end users. I bring this up because my job as a DevOps Consultant is to delivering value to my end users. But not all of us do. My amazing coworker (@_s_hari) and I have discussions about this quite a bit. As far as I know, he coined the term and gave me his blessing to blog about it.

What is DevOps?

·230 words·2 mins
What Isn’t DevOps? # Before I define DevOps, let’s get started with what DevOps isn’t. DevOps isn’t just a title, or a guy, or a department. DevOps isn’t just automating everying, and isn’t just logging everything. DevOps isn’t dozens of alerts every day, and isn’t an on-call rotation. DevOps isn’t agile or small releases. DevOps is a mindset.