CentralConfigGenerator 1.0.0
See the version list below for details.
dotnet tool install --global CentralConfigGenerator --version 1.0.0
dotnet new tool-manifest
dotnet tool install --local CentralConfigGenerator --version 1.0.0
#tool dotnet:?package=CentralConfigGenerator&version=1.0.0
nuke :add-package CentralConfigGenerator --version 1.0.0
CentralConfigGenerator
Goals
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.
Terms of use
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! 🇺🇦
Overview
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 - Updating your project files to use these centralized configurations
Installation
dotnet tool install --global CentralConfigGenerator
Usage
Basic Commands
CentralConfigGenerator provides three 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 both files in one command
central-config all [options]
Command 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
Examples
Generate Directory.Build.props
# 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
# 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
Generate Both Files
# Generate both files in one command
central-config all
# Generate both files with all options
central-config all -d C:\Projects\MySolution -o -v
How It Works
Directory.Build.props Generation
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
Directory.Packages.props Generation
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
Understanding the Generated Files
Directory.Build.props
<Project>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Directory.Packages.props
<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>
Benefits
- 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
Common Scenarios
Migrating Existing Solutions
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
Limitations
- 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
Local installation
To install the tool locally for development or testing, clone the repository and run:
dotnet tool install --global --add-source .\CentralConfigGenerator\nupkg\ CentralConfigGenerator
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.