Skip to content

Repository files navigation

dotnet-solution-cleaner

Clean up NuGet sprawl, migrate to Central Package Management, and consolidate your .NET solution.

Large .NET solutions accumulate technical debt: duplicate NuGet package versions across projects, unused package references, inconsistent TargetFrameworks, and no Central Package Management. dotnet-solution-cleaner automates the cleanup.

Installation

dotnet tool install -g dotnet-solution-cleaner

Quick Start

# Full analysis report
dotnet solution-cleaner analyze

# Find unused NuGet packages
dotnet solution-cleaner unused

# Migrate to Central Package Management (preview first)
dotnet solution-cleaner migrate-cpm --dry-run
dotnet solution-cleaner migrate-cpm

# Extract common properties to Directory.Build.props
dotnet solution-cleaner consolidate --dry-run
dotnet solution-cleaner consolidate

# Undo the last operation
dotnet solution-cleaner restore

Commands

analyze

Produces a full report of the solution:

  • Project count and package statistics
  • Package version matrix across all projects
  • Version conflicts highlighted
  • Common properties that can be extracted to Directory.Build.props
  • Potentially unused packages
dotnet solution-cleaner analyze [path-to.sln]

unused

Scans for NuGet packages that are referenced but never used in code. Detection is heuristic — it checks using directives against package namespaces. Review results before removing packages.

dotnet solution-cleaner unused [path-to.sln]

migrate-cpm

Migrates the solution to Central Package Management:

  • Generates Directory.Packages.props with all package versions
  • Removes Version attributes from .csproj PackageReferences
  • Reports and resolves version conflicts (highest version wins)
dotnet solution-cleaner migrate-cpm [path-to.sln] [--dry-run]

consolidate

Identifies properties common across all projects (TargetFramework, LangVersion, Nullable, ImplicitUsings, etc.) and extracts them to Directory.Build.props.

dotnet solution-cleaner consolidate [path-to.sln] [--dry-run]

restore

Undoes the last migrate-cpm or consolidate operation by restoring files from the backup created before the operation.

dotnet solution-cleaner restore [path-to.sln]

How It Works

  • Solution parsing: Reads .sln files to discover projects
  • Project parsing: Uses System.Xml.Linq for clean XML manipulation of .csproj files
  • Unused detection: Scans .cs files for using directives and cross-references with package namespaces (heuristic)
  • Backup/restore: All modifications are backed up to .solution-cleaner-backup/ before applying

Options

All commands accept an optional [path] argument pointing to the .sln file. If omitted, the tool looks for a single .sln file in the current directory.

The migrate-cpm and consolidate commands support --dry-run to preview changes without modifying files.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Run dotnet test and dotnet format
  5. Submit a pull request

License

MIT

About

Clean up NuGet sprawl, migrate to Central Package Management, and consolidate .NET solutions

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages