This document explains how CentralConfigGenerator uses NuGet.Versioning to provide advanced version management capabilities.
CentralConfigGenerator uses the NuGet.Versioning package to provide sophisticated version handling that goes beyond basic .NET version comparison. This integration enables proper semantic versioning support, version range handling, and accurate package version conflict resolution.
The tool properly handles semantic versioning (SemVer) including:
- Major.Minor.Patch versions (e.g.,
1.2.3) - Pre-release tags (e.g.,
1.0.0-beta.1,2.0.0-rc.2) - Build metadata (e.g.,
1.0.0+build.123)
<!-- Pre-release versions are correctly compared -->
<PackageReference Include="MyPackage" Version="1.0.0-alpha.1" />
<PackageReference Include="MyPackage" Version="1.0.0-beta.1" />
<!-- Result: 1.0.0-beta.1 is selected as it's newer than alpha -->Supports NuGet's version range syntax:
- Exact version:
1.0.0 - Minimum version:
1.0.0 - Exact range:
[1.0.0] - Minimum inclusive:
[1.0.0,) - Maximum inclusive:
(,1.0.0] - Range:
[1.0.0,2.0.0) - Floating version:
1.0.*
<!-- Version ranges are preserved and understood -->
<PackageReference Include="MyPackage" Version="[1.0.0,2.0.0)" />
<PackageReference Include="MyPackage" Version="1.5.0" />
<!-- Result: [1.0.0,2.0.0) is selected as it encompasses the specific version -->The enhanced package analyzer provides multiple strategies for resolving version conflicts:
- Highest Version (Default): Selects the highest version among all referenced versions
- Lowest Version: Selects the lowest version (useful for maximum compatibility)
- Most Common: Selects the version used by most projects
- Manual: Prompts for manual intervention when automatic resolution isn't suitable
// Using the version conflict resolver
var resolver = new VersionConflictResolver();
var resolvedVersion = resolver.Resolve(
"Newtonsoft.Json",
new[] { "11.0.2", "12.0.3", "13.0.1" },
VersionResolutionStrategy.Highest
);
// Result: "13.0.1"The tool can check for known issues with specific package versions:
- Security vulnerabilities
- Performance regressions
- Breaking changes
- Deprecated versions
Warnings:
┌─────────┬─────────────────────┬─────────────────────────────────────────────┐
│ Level │ Package │ Message │
├─────────┼─────────────────────┼─────────────────────────────────────────────┤
│ Warning │ Newtonsoft.Json │ Known security vulnerability in version 9.x │
│ Info │ System.Text.Json │ Pre-release version detected │
│ Warning │ EntityFramework │ This version is significantly outdated │
└─────────┴─────────────────────┴─────────────────────────────────────────────┘
The tool uses NuGetVersion.TryParse() instead of the basic Version.TryParse():
// Old approach (limited)
if (Version.TryParse(versionStr, out var version))
{
// Only handles numeric versions like "1.0.0"
}
// New approach (comprehensive)
if (NuGetVersion.TryParse(versionStr, out var nugetVersion))
{
// Handles "1.0.0-beta.1+build.123" and more
}NuGet.Versioning provides accurate version comparison following SemVer rules:
var v1 = NuGetVersion.Parse("1.0.0-alpha");
var v2 = NuGetVersion.Parse("1.0.0-beta");
var v3 = NuGetVersion.Parse("1.0.0");
// Correct ordering: alpha < beta < release
Console.WriteLine(v1 < v2); // True
Console.WriteLine(v2 < v3); // TrueThe tool handles various special version formats:
- Variables:
$(VersionPrefix)$(VersionSuffix) - Properties:
$(MyPackageVersion) - Wildcards:
1.0.* - Floating:
1.*
These are preserved in the output when they cannot be resolved to specific versions.
The enhanced package analyzer provides detailed visual reports using Spectre.Console:
Package Analysis Summary
┌─────────────────────────┬─────────┐
│ Metric │ Value │
├─────────────────────────┼─────────┤
│ Total Packages │ 25 │
│ Packages with Conflicts │ 5 │
│ Warnings │ 8 │
└─────────────────────────┴─────────┘
Resolved Package Versions:
┌─────────────────────────────┬─────────────────┐
│ Package │ Version │
├─────────────────────────────┼─────────────────┤
│ Microsoft.Extensions.Logging│ 8.0.0 │
│ Newtonsoft.Json │ 13.0.3 │
│ NuGet.Versioning │ 6.7.0 │
└─────────────────────────────┴─────────────────┘
- Use Semantic Versioning: Follow SemVer conventions for your package versions
- Avoid Floating Versions: Use specific versions in production code
- Review Conflicts: Always review detected conflicts before accepting resolutions
- Check Compatibility: Pay attention to compatibility warnings
- Test After Migration: Test your solution after centralizing package versions
-
Unparseable Versions: Some version formats (like variables) cannot be parsed
- Solution: These are preserved as-is in the output
-
Complex Version Ranges: Overlapping ranges might cause unexpected resolutions
- Solution: Review the resolution and adjust manually if needed
-
Pre-release Dependencies: Pre-release packages in production code
- Solution: The tool warns about these; consider using stable versions
Run with verbose logging to see detailed version analysis:
central-config packages-enhanced -vThis will show:
- Each version comparison
- Resolution decisions
- Parsing failures
- Compatibility check results
EnhancedPackageAnalyzer: Main analyzer with conflict detectionVersionConflictResolver: Resolves version conflicts using various strategiesVersionCompatibilityChecker: Checks for known version issuesVersionConflictVisualizer: Creates visual reports of analysis results