Skip to main content
← back to field notes
2 min readDevelopment

Clearing NuGet Package Caches

developmentdotnetnuget

How to Clear Your NuGet Caches

NuGet caches downloaded packages to avoid lengthy update times. While this is generally helpful, it can sometimes lead to issues, especially when restoring packages in environments like CI servers. Below is a guide to clearing your NuGet caches to help debug and resolve restore problems.

Why Clear NuGet Caches?

Clearing NuGet caches can resolve issues such as:

  • Corrupted or outdated package files.
  • Conflicts between different versions of the same package.
  • Problems with package restore in CI/CD pipelines.

Manually Clearing Folders

To manually clear NuGet caches, remove the following folders:

- Packages Folder (In Project)
- %userprofile%\.nuget\packages
- %localappdata%\NuGet\Cache
- %localappdata%\NuGet\v3-cache
- %localappdata%\NuGet\plugins-cache

Using the CLI

The NuGet CLI and .NET CLI provide commands to clear specific caches or all caches at once. Here’s how to use them:

# 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

Pro Tips

  1. Automate Cache Clearing: Use scripts to automate cache clearing in CI/CD pipelines to avoid manual intervention.
  2. Verify Cache Clearing: After clearing caches, run dotnet restore or nuget restore to ensure packages are restored correctly.
  3. Use with Caution: Clearing caches can lead to longer restore times as packages are re-downloaded. Use this method only when necessary.

Final Thoughts

Clearing NuGet caches is a simple yet effective way to resolve package-related issues. Whether you’re debugging a local project or troubleshooting a CI/CD pipeline, these steps can save you time and frustration. Remember to use these commands judiciously to maintain efficient workflows.

field notes

you may also enjoy

more from this thread of thought

working with git: archive
Aug 5, 2025

working with git: archive

read more →
Surprise Driven Development
Jul 10, 2025

Surprise Driven Development

read more →
What's in a .git? A Deep Dive into Git's Hidden Engine
Jun 3, 2025

What's in a .git? A Deep Dive into Git's Hidden Engine

read more →
Git Worktrees: Multiple Branches, Zero Context Switching
May 30, 2025

Git Worktrees: Multiple Branches, Zero Context Switching

read more →
Walking Back with Git: HEAD^ vs HEAD~ Demystified
May 29, 2025

Walking Back with Git: HEAD^ vs HEAD~ Demystified

read more →
New Project Release: Pride Flags
May 5, 2025

New Project Release: Pride Flags

read more →
the field notes

recently written