A robust Semantic Versioning 2.0.0 implementation for .NET with full support for parsing, comparison, and version operations.
Install via NuGet Package Manager:
dotnet add package tetri.net.SemanticVersioningOr add directly to your .csproj:
<PackageReference Include="tetri.net.SemanticVersioning" Version="0.2.2" />// From string
var version = new SemanticVersion("1.2.3-alpha.1+20240301");
// Using constructor
var version = new SemanticVersion(major: 1, minor: 2, patch: 3, prerelease: "alpha.1", build: "20240301");var v1 = new SemanticVersion("1.2.3");
var v2 = new SemanticVersion("1.3.0");
if (v1 < v2)
{
Console.WriteLine($"{v1} is less than {v2}");
}// Equality
bool equal = v1 == v2;
// Comparison
bool greater = v1 > v2;
// Comparison methods
int result = v1.CompareTo(v2);β
Strict SemVer 2.0.0 string parsing
β
Full version comparison support
β
Pre-release support (alpha, beta, rc)
β
Build metadata support
β
Overloaded operators (==, !=, <, >, <=, >=)
β
Immutable and thread-safe
β
JSON/XML serialization ready
var stable = new SemanticVersion("1.0.0");
var beta = new SemanticVersion("1.0.0-beta.2");
Console.WriteLine(stable > beta); // True - stable versions have precedencevar v1 = new SemanticVersion("1.0.0+build.1");
var v2 = new SemanticVersion("1.0.0+build.2");
Console.WriteLine(v1 == v2); // True - build metadata doesn't affect equality- .NET 9.0 SDK or later
- Git
git clone https://github.com/tetri/SemanticVersioning.git
cd SemanticVersioning
# Enable commit hooks
dotnet tool restore 2>$null
git config core.hooksPath .githooks
# Build and test
dotnet build
dotnet testThis project enforces Conventional Commits.
type(optional-scope): description
Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
The .githooks/commit-msg hook validates every commit locally. Pull requests are also validated in CI.
We welcome contributions! Please read CONTRIBUTING.md for full guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
Crafted with π§ by Tetri Mesquita