pkg-trim 1.0.2

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

pkg-trim

pkg-trim is a simple .NET CLI tool that analyzes your solution and identifies unused <PackageVersion> entries in your Directory.Packages.props file. Optionally, it can clean them up for you automatically.

Features

  • Scans all .csproj and Directory.Build.props files for used PackageReferences
  • Compares them against the declared PackageVersions in Directory.Packages.props
  • Identifies unused package versions
  • Supports an optional --fix flag to automatically remove unused packages

Installation

dotnet tool install --global pkg-trim

Usage

pkg-trim [--sln-dir <path>] [--fix]

Options

  • --sln-dir or --solution-directory
    Path to the root directory of your solution (where Directory.Packages.props is located).
    If omitted, the tool will use the directory of the executable as default.

  • --fix
    If specified, removes the unused packages from Directory.Packages.props.
    Without this flag, the tool only lists the unused entries.

Example

pkg-trim --sln-dir /path/to/solution
pkg-trim --fix

How It Works

  1. Scans all .csproj and Directory.Build.props files recursively in the provided solution directory.
  2. Collects all used PackageReference names.
  3. Loads the Directory.Packages.props file and checks for <PackageVersion> entries that are no longer used.
  4. Lists them in the output, and removes them if --fix is passed.

Why

Over time, projects accumulate package versions that are no longer used. Keeping your Directory.Packages.props file clean helps:

  • Reduce confusion and clutter
  • Improve maintainability of your solution

License

MIT

Product Compatible and additional computed target framework versions.
.NET 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. 
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.2 145 3/22/2025
1.0.1 142 3/22/2025
1.0.0 144 3/22/2025