DEV Community

Cover image for Safe cleaning NuGet cache.
Serhii Korol
Serhii Korol

Posted on

Safe cleaning NuGet cache.

Hi folks! I want to discuss about NuGet packages. If you frequently work with different .NET projects, you will eventually encounter disk overflow. This has been caused by Dotnet downloading NuGet packages to your disk. When you rerun your project, Dotnet doesn't waste time downloading from the NuGet server, and it gets from the cache on your disk. It provisions much faster running. But that's the problem. The same NuGet package can contain several versions, newest and older. The older version you don't need. And you can delete it from the cache. Another case is that you have Nuget packages you don't use anymore. You also can remove it. What if you have hundreds of NuGet packages? For now, I have 1438 packages, which exclude different versions, and it takes over 20 GB of disk space with various versions. The packages are stored in the .nuget folder. From time to time, it needs to be cleaned. I'll show you how to do it.

folder info

You can waste time manually removing non-actual packages, for sure. I suggest a way to clean NuGet packages. After that, you need to re-download the needed packages. However, it allows you to eliminate obsolete and oldest packages, which you'll not use again. Just run this command in the Terminal:

dotnet nuget locals all --clear
Enter fullscreen mode Exit fullscreen mode

The result should be like this:

terminal

I hope this tip will help you to clean your disk from the garbage and free space on your PC. Happy coding!

Buy Me A Beer

Top comments (0)