A command-line tool that helps you quickly migrate large .NET solutions to Central Package Management (CPM). CPMGen automatically generates Directory.Packages.props files and updates your .csproj files, making the transition to centralized package management effortless.
Migrating large solutions with multiple projects to Central Package Management can be tedious and error-prone. CPMGen automates this process, allowing you to modernize your .NET solution's package management in seconds instead of hours.
- 🔍 Automatically scans for
.slnor.csprojfiles in your solution, or you can tell it where to look - 📦 Generates
Directory.Packages.propswith all package versions centralized - 🔄 Updates project files to remove version attributes automatically
- 💾 Built-in backup functionality to keep your original files safe
- 🚫 Optional
.gitignoreintegration for backup directories
# Install as a global .NET tool
dotnet tool install --global CPMGenAfter installation, the CPMGen command will be available globally in your terminal.
# Convert all projects in current directory
CPMGen
# Convert projects in a specific solution
CPMGen -s path/to/solution
# Convert a specific project
CPMGen -p path/to/project.csproj| Option | Short | Description | Default |
|---|---|---|---|
--solution |
-s |
Directory to search for .sln files (overrides project option) |
. (current directory) |
--project |
-p |
Directory or path to .csproj file(s) |
- |
--output-dir |
-o |
Output directory for Directory.Packages.props |
. (current directory) |
--keep-attrs |
-k |
Keep Version attributes in .csproj files |
false |
--no-backup |
-n |
Disable automatic backup of .csproj files |
false |
--backup-dir |
- | Directory for backing up modified .csproj files |
. (current directory) |
--add-gitignore |
- | Add backup directory to .gitignore (creates if missing) |
false |
--gitignore-dir |
- | Directory for .gitignore |
. (current directory) |
# Default behavior - convert all projects in current directory
CPMGen
# Convert only a specific project
CPMGen -p path/to/project.csproj
# Specify custom output directory
CPMGen -o ../upDir
# Convert solution with custom backup location
CPMGen -s ./src --backup-dir ./backups --add-gitignore
# Convert without creating backups
CPMGen -n
# Keep version attributes in project files
CPMGen -kCentral Package Management (CPM) is a NuGet feature that allows you to manage all your package versions in a single Directory.Packages.props file rather than scattered across individual project files. This provides:
- Consistency: Ensures all projects use the same package versions
- Maintainability: Update a package version in one place, apply everywhere
- Reduced conflicts: Fewer merge conflicts in project files during team collaboration
- Better overview: See all your dependencies and versions at a glance
On a standard execution:
- You run
cpmgen - Scans the current directory for
.slnfiles, if multiple are found you can choose one - Parses all the projects defined in the
.slnfile - Backs up all the
.csprojfiles it'll have to udpate so you won't lose any data - Generates the
Directory.Packages.propsfile with all the packages + versions found in all the projects - Updates the
.csprojfiles to removeVersionattributes from package references
- .NET SDK: Currently the tool is configured to be built for
.NETversions 8 & 9, but I'll add other versions support soon - Project Format: SDK-style
.csprojfiles (the modern XML format) - Operating System: Windows, macOS, or Linux
CPMGen works with SDK-style projects introduced in 2017. It does not support the legacy .csproj format used in older .NET Framework projects. If you have a mixed solution, only SDK-style projects will be processed.
Contributions are welcome! Whether it's bug reports, feature requests, or code contributions, your input helps make CPMGen better for everyone.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License. It provides maximum flexibility, allowing you to use, modify, distribute, and sublicense the software with minimal restrictions. See the LICENSE file for details.
If you encounter any issues or have questions:
Built to simplify the adoption of NuGet's Central Package Management feature in the .NET ecosystem.
