nuget-cpm-cleaner 1.0.1

dotnet tool install --global nuget-cpm-cleaner --version 1.0.1
                    
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 nuget-cpm-cleaner --version 1.0.1
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=nuget-cpm-cleaner&version=1.0.1
                    
nuke :add-package nuget-cpm-cleaner --version 1.0.1
                    

nuget-cpm-cleaner

A .NET global tool that removes unused <PackageVersion> entries from your Directory.Packages.props file (NuGet Central Package Management).

The Problem

When using NuGet CPM, over time packages get removed from .csproj files but their version declarations stay behind in Directory.Packages.props, causing noise and potential confusion.

How It Works

  1. Locates Directory.Packages.props starting from the specified root (walks up directories if needed)
  2. Parses all <PackageVersion> entries — the "declared" packages
  3. Recursively scans all .csproj and Directory.Build.props files for <PackageReference> entries — the "used" packages
  4. Computes the difference: declared − used = unused
  5. Either prompts you to select which ones to remove, or removes all automatically

Installation

dotnet tool install -g nuget-cpm-cleaner

Usage

Interactive mode (default)

Displays a multi-select prompt listing all unused packages. Use space to toggle, enter to confirm.

nuget-cpm-cleaner --root C:/repos/my-solution

Auto-remove mode

Removes all unused packages without prompting.

nuget-cpm-cleaner --root . --auto-remove

Options

Option Description Default
--root Path to the repository root Current directory
--auto-remove Remove all unused packages without prompting false

Example Output

Found C:\repos\my-solution\Directory.Packages.props
Declared packages: 42
Referenced packages across .csproj files: 38

Found 4 unused package(s):

? Select packages to remove: (Press <space> to toggle, <enter> to confirm)
> [ ] Deprecated.Package
  [ ] OldLibrary.Core
  [ ] SomeUnused.Tool
  [ ] UnusedAnalyzer

Done. Removed 2 package(s) from Directory.Packages.props:
  - Deprecated.Package
  - OldLibrary.Core

Requirements

  • .NET 10 or later

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.0.1 177 3/22/2026
1.0.0 113 3/22/2026