No description
Find a file
Louis Seubert a576264223
All checks were successful
default / dotnet-default-workflow (push) Successful in 1m3s
wip
2026-05-21 21:29:21 +02:00
.forgejo/workflows wip 2026-05-16 23:04:09 +02:00
src wip 2026-05-21 21:29:21 +02:00
.editorconfig wip 2026-05-21 21:29:21 +02:00
.gitignore feat: add initial project setup 2026-04-05 08:23:42 +02:00
CHANGELOG.md wip 2026-05-21 21:29:21 +02:00
Directory.Build.props feat: add initial project setup 2026-04-05 08:23:42 +02:00
Directory.Build.targets feat: add initial project setup 2026-04-05 08:23:42 +02:00
Directory.Packages.props feat: add initial project setup 2026-04-05 08:23:42 +02:00
global.json feat: add initial project setup 2026-04-05 08:23:42 +02:00
LICENSE.md feat: add initial project setup 2026-04-05 08:23:42 +02:00
nuget.config feat: add initial project setup 2026-04-05 08:23:42 +02:00
README.md wip 2026-05-21 21:29:21 +02:00
semver.slnx wip 2026-05-12 22:21:24 +02:00

Geekeey.SemVer

SemVer is a .NET library for parsing and comparing semantic version numbers. It provides a simple API for working with semantic versioning, making it easy to manage version numbers in your .NET projects.

Features

  • Parsing: Parse semantic version strings into structured objects.
  • Comparison: Compare semantic version objects to determine their order.
  • Validation: Validate semantic version strings to ensure they conform to the SemVer specification.
  • Pre-release and Build Metadata: Support for pre-release versions and build metadata as defined in the SemVer specification.

Getting Started

Install the NuGet package:

dotnet add package Geekeey.SemVer

You may need to add our NuGet feed to your nuget.config this can be done by running the following command:

dotnet nuget add source -n geekeey https://code.geekeey.de/api/packages/geekeey/nuget/index.json

Usage

using Geekeey.SemVer;

var version = SemanticVersion.Parse("1.2.3-beta+build.7");
var next = new SemanticVersion(1, 3, 0);

Console.WriteLine(version);
Console.WriteLine(version.Major);
Console.WriteLine(version.Prerelease);
Console.WriteLine(version.Metadata);
Console.WriteLine(version < next);

You can also use TryParse when you need to handle invalid input without exceptions.

using Geekeey.SemVer;

if (SemanticVersion.TryParse("1.2.3-alpha", out var parsed))
{
  Console.WriteLine(parsed);
}

Version ranges support npm-style and Maven-style syntax.

using Geekeey.SemVer;

var npmRange = SemanticVersionRange.Parse("^1.2.3");
var mavenRange = SemanticVersionRange.Parse("[1.2.3,2.0.0)");
var candidate = SemanticVersion.Parse("1.4.2");

Console.WriteLine(npmRange.Contains(candidate));
Console.WriteLine(mavenRange.Contains(candidate));
Console.WriteLine(npmRange.ToString("m", null));
Console.WriteLine(mavenRange.ToString("ns", null));

Both SemanticVersion and SemanticVersionRange integrate with System.Text.Json.

using System.Text.Json;
using Geekeey.SemVer;

var version = SemanticVersion.Parse("1.2.3-beta+build.7");
var range = SemanticVersionRange.Parse("^1.2.3");

var versionJson = JsonSerializer.Serialize(version);
var rangeJson = JsonSerializer.Serialize(range);

var roundTrippedVersion = JsonSerializer.Deserialize<SemanticVersion>(versionJson);
var roundTrippedRange = JsonSerializer.Deserialize<SemanticVersionRange>(rangeJson);