Articles in this section
Category / Section

How to clear NuGet cache?

5 mins read

Whenever a new NuGet package is installed, the NuGet package will be stored in NuGet cache location and afterwards that particular NuGet package with same version will be referred from the cache location instead of the package sources that we are configured in package manger/packages.config. If some NuGet package is updated/refreshed/patched with some additional changes with same version, it is always better to clear NuGet cache before install the updated NuGet package with same version.

 

We can clear the NuGet cache locations either using Visual Studio or Command Line Interface.

 

Using Visual Studio

 

  1. Open Visual Studio, go to Tools -> NuGet Package Manager -> Package Manager Settings menu.
     
  2. Click Clear All NuGet Cache(s) button in options dialog then clearing process is started.

    NuGet Cache clear form Visual Studio

  3. Once NuGet cache location is cleared, click ok button.

 

Using Command Line Interface

  1. Download the latest NuGet executable from here.

  2. Navigate the directory of the downloaded exe in command window and run the following command. 

 

OS

Command

Windows

nuget locals <all | http-cache | packages-cache | global-packages | temp> -clear

Mac

mono nuget.exe locals <all | http-cache | packages-cache | global-packages | temp> -clear

 

 For Example:

Windows:

Command: nuget locals all -clear

NuGet Cache clear form CLI

Mac:

Command: mono nuget.exe locals all -clear

Mac nuget cache clear command

 


Now the NuGet packages will get removed from cache location.

Note:

The above process will clear all the NuGet packages from cache location. So once cleared the NuGet cache location then every NuGet package will be downloaded/restored from source location to cache location again. If we want to avoid this case, we can navigate to NuGet cache location and delete the particular NuGet package manually. Find the NuGet cache locations by using the below command.

 

Windows:

Commandnuget locals all -list

NuGet Cache location list form CLI

Mac:

 

Command: mono nuget.exe locals all -list

 

Mac nuget cache location list command

 

Navigate the listed cache locations by file explorer (Windows)/finder (Mac) and remove the unrequired NuGet packages manually.

 

 

 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied