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.
dotnet tool install -g dotnet-solution-cleaner# 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 restoreProduces 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]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]Migrates the solution to Central Package Management:
- Generates
Directory.Packages.propswith all package versions - Removes
Versionattributes from.csprojPackageReferences - Reports and resolves version conflicts (highest version wins)
dotnet solution-cleaner migrate-cpm [path-to.sln] [--dry-run]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]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]- Solution parsing: Reads
.slnfiles to discover projects - Project parsing: Uses
System.Xml.Linqfor clean XML manipulation of.csprojfiles - Unused detection: Scans
.csfiles forusingdirectives and cross-references with package namespaces (heuristic) - Backup/restore: All modifications are backed up to
.solution-cleaner-backup/before applying
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.
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Run
dotnet testanddotnet format - Submit a pull request