NuGetCleaner 1.1.3

dotnet tool install --global NuGetCleaner --version 1.1.3                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local NuGetCleaner --version 1.1.3                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=NuGetCleaner&version=1.1.3                
nuke :add-package NuGetCleaner --version 1.1.3                

image

Last commit NuGet

About

The Global Packages Folder is where all packages installed through the NuGet package manager tool on Visual Studios are stored. When packages are no longer in use becuase a user has updated their packages for a project or has moved on to other projects, those unused packages remain in the GPF and continue to take up storage. It is not uncommon for the folder to have several Gigabytes of unnecessary package data after long-term use.

nugetcleaner is the solution! It is a global .NET CLI tool that deletes packages that haven't been used to build a project in a number of days specified by the user.

Get started

Installation

nugetcleaner is available as a .NET Core Global Tool:

dotnet tool install --global NuGetCleaner

The latest version can also be downloaded directly from NuGet.org at: https://www.nuget.org/packages/NuGetCleaner/

Prerequisites

nugetcleaner makes use of last access timestamp updates which are disabled by default in Windows 7, 8, and 10. In order to use the tool, last access updates must be enabled.

In order to enable last access updates, run Windows PowerShell or Command Prompt in administrator mode and enter:

fsutil behavior set disablelastaccess 2

You may be prompted to reboot afterwards for the settings change to take effect.

Usage

nugetcleaner [--dry-run] --days <# of days>

--dry-run - (Optional) List packages that would be deleted given the specified number of days, but don't actually delete them.

--days <# of days> - (Required) Packages last accessed (used in a project build) on the number of days in the past specified or greater are selected for deletion.

Examples

Example 1: Delete packages that have not been accessed in 60 or more days.

nugetcleaner --days 60

Example 2: List packages that have not been accessed in 90 or more days, but don't delete them.

nugetcleaner --dry-run --days 90

How It Works

nugetcleaner works by checking the last access date of all the packages in the global package folder and deleting ones with last access timestamps that exceed the age in days specified by the user. To be clear, it will check each version of a package and delete only the versions that exceed the age. For example, if there are multiple versions in the "newtonsoft.json" folder and only the most recent version has been used within the time constraint, then only the older version will be deleted. The "newtonsoft.json" parent directory will remain with the lastest version. However, if none of the versions were used within the time constraint, then all versions along with the parent folder will be deleted. At the end of the cleaning process, no empty folders will remain.

Use Warning:

If the cleaning process is activated immediately after last access updates enabled, before ongoing projects have been updated or built (thus accessing the relevant packages), then deletion will be determined solely by package installation date as last access timestamps wouldn't have had time to update. If this is an undesirable outcome, then it is highly recommended that the user waits until ongoing/relevant projects have been updated or built with last access timestamps enabled before using nugetcleaner to clean out the global package folder. If you're interested in seeing the potential outcome of the cleaning process before going through with it, enable --dry-run to see a preview of the packages that would be deleted.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.1.3 1,164 10/20/2021
1.1.2 400 10/20/2021
1.1.1 402 10/20/2021
1.1.0 460 4/21/2021
1.0.8 658 9/17/2019
1.0.4 921 9/11/2019