A modern .NET tool for automatically generating centralized configuration files for .NET projects. CentralConfig analyzes your solution structure and creates properly configured Directory.Build.props
and Directory.Packages.props
files to standardize settings across your projects.
By using this project or its source code, for any purpose and in any shape or form, you grant your implicit agreement to all of the following statements:
- You unequivocally condemn Russia and its military aggression against Ukraine
- You recognize that Russia is an occupant that unlawfully invaded a sovereign state
- You agree that Russia is a terrorist state
- You fully support Ukraine's territorial integrity, including its claims over temporarily occupied territories
- You reject false narratives perpetuated by Russian state propaganda
To learn more about the war and how you can help, click here. Glory to Ukraine! 🇺🇦
CentralConfigGenerator helps you maintain consistent configuration across multiple .NET projects by:
- Automatically generating
Directory.Build.props
files with common project properties - Automatically generating
Directory.Packages.props
files with centralized package versions - Providing advanced version conflict resolution using NuGet.Versioning
- Offering compatibility checking and visual analysis of version conflicts
- Updating your project files to use these centralized configurations
dotnet tool install --global CentralConfigGenerator
CentralConfigGenerator provides four main commands:
# Generate Directory.Build.props file with common project properties
central-config build [options]
# Generate Directory.Packages.props file for centralized package versions
central-config packages [options]
# Generate Directory.Packages.props with enhanced version analysis
central-config packages-enhanced [options]
# Generate both files in one command
central-config all [options]
All commands support the following options:
-d, --directory <PATH>
: Specify the directory to scan (defaults to current directory)-o, --overwrite
: Overwrite existing files (off by default)-v, --verbose
: Enable verbose logging
# Generate Directory.Build.props in the current directory
central-config build
# Generate in a specific directory and overwrite if exists
central-config build -d C:\Projects\MySolution -o
# Generate Directory.Packages.props in the current directory
central-config packages
# Generate in a specific directory with verbose logging
central-config packages -d C:\Projects\MySolution -v
# Use enhanced package analysis with visual conflict resolution
central-config packages-enhanced -d C:\Projects\MySolution -v
# This will:
# - Detect version conflicts across projects
# - Show visual analysis of conflicts
# - Suggest resolutions based on semantic versioning
# - Check for compatibility issues
# - Ask for confirmation before proceeding
The build
command:
- Scans all
.csproj
files in the specified directory and subdirectories - Identifies common properties that appear in multiple projects
- Extracts these properties into a
Directory.Build.props
file - Removes the extracted properties from individual project files
By default, CentralConfigGenerator will focus on the following key properties:
TargetFramework
ImplicitUsings
Nullable
The packages
command:
- Scans all
.csproj
files in the specified directory and subdirectories - Extracts all package references and their versions
- For each package, uses the highest version found across all projects
- Generates a
Directory.Packages.props
file with these package versions - Removes version attributes from
PackageReference
elements in project files
The packages-enhanced
command provides advanced features:
- Semantic Version Analysis: Uses NuGet.Versioning for accurate version comparisons
- Conflict Detection: Identifies and visualizes version conflicts across projects
- Version Range Support: Handles version ranges (e.g.,
[1.0.0,2.0.0)
) - Pre-release Detection: Warns about pre-release packages in production code
- Compatibility Checking: Identifies known issues with specific package versions
- Visual Reports: Provides clear, color-coded reports of analysis results
- Multiple Resolution Strategies: Offers different approaches to resolve conflicts:
- Highest version (default)
- Lowest version
- Most common version
- Manual resolution
<Project>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
<PackageVersion Include="Spectre.Console" Version="0.50.0" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.50.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
</Project>
When multiple projects reference the same package with different versions, the enhanced analyzer:
- Detects all version conflicts
- Shows a detailed conflict report
- Applies resolution strategy (highest version by default)
- Asks for confirmation before proceeding
Example output:
Package Analysis Summary
┌─────────────────────────┬─────────┐
│ Metric │ Value │
├─────────────────────────┼─────────┤
│ Total Packages │ 12 │
│ Packages with Conflicts │ 3 │
│ Warnings │ 5 │
└─────────────────────────┴─────────┘
Version Conflicts Detected:
┌─────────────────────┬──────────────────┬─────────────┬─────────────┐
│ Package │ Project │ Version │ Type │
├─────────────────────┼──────────────────┼─────────────┼─────────────┤
│ Newtonsoft.Json │ Project1.csproj │ 11.0.2 │ Release │
│ Newtonsoft.Json │ Project2.csproj │ 13.0.3 │ Release │
└─────────────────────┴──────────────────┴─────────────┴─────────────┘
The enhanced analyzer properly handles:
- Pre-release versions (e.g.,
1.0.0-beta.1
) - Build metadata (e.g.,
1.0.0+build.123
) - Version ranges (e.g.,
[1.0.0,2.0.0)
) - Floating versions (e.g.,
1.0.*
)
The tool can warn about:
- Known security vulnerabilities in specific versions
- Performance issues in certain package versions
- Significantly outdated packages
- Pre-release packages in production code
- Consistent Configuration: Ensure all projects use the same framework versions, language features, and code quality settings
- Simplified Updates: Update package versions or project settings in a single location
- Reduced Duplication: Remove redundant configuration from individual project files
- Improved Maintainability: Make your solution more maintainable by centralizing common settings
- Version Conflict Resolution: Automatically detect and resolve package version conflicts
- Better Version Management: Use semantic versioning for accurate version comparisons
- Visual Analysis: See clear, color-coded reports of package analysis results
For existing solutions with many projects, use CentralConfigGenerator to centralize configuration:
# Navigate to the solution root
cd MySolution
# Generate both configuration files with verbose output
central-config all -v
When you have multiple projects with conflicting package versions:
# Use enhanced package analysis to detect and resolve conflicts
central-config packages-enhanced -v
# The tool will:
# 1. Show all version conflicts
# 2. Propose resolutions
# 3. Ask for confirmation
# 4. Update all project files
- Projects with highly customized or conflicting settings may require manual adjustment after running CentralConfigGenerator
- For properties to be included in Directory.Build.props, they must appear with identical values in most projects
- Version conflicts in packages will be resolved by selecting the highest version found (configurable in enhanced mode)
- Some version formats (like variables) cannot be automatically resolved
To install the tool locally for development or testing, clone the repository and run:
dotnet tool install --global --add-source .\CentralConfigGenerator\nupkg\ CentralConfigGenerator
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.