No description
Find a file
Louis Seubert 98f4a2165e
All checks were successful
default / dotnet-default-workflow (push) Successful in 1m4s
chore: remove package description from the readme
This removes the description from the package readme. The desciption of the package is
shown on nuget.org in the list view and if no package readme is defined on the detail view of
a package version. Since we provide a package readme we do not need the description shown
twice.
2026-05-21 22:00:59 +02:00
.forgejo/workflows feat: add initial project setup 2026-05-21 21:45:36 +02:00
src chore: remove package description from the readme 2026-05-21 22:00:59 +02:00
.editorconfig feat: add initial project setup 2026-05-21 21:45:36 +02:00
.gitignore feat: add initial project setup 2026-05-21 21:45:36 +02:00
CHANGELOG.md feat: add initial project setup 2026-05-21 21:45:36 +02:00
Directory.Build.props feat: add initial project setup 2026-05-21 21:45:36 +02:00
Directory.Build.targets feat: add initial project setup 2026-05-21 21:45:36 +02:00
Directory.Packages.props feat: add initial project setup 2026-05-21 21:45:36 +02:00
global.json feat: add initial project setup 2026-05-21 21:45:36 +02:00
LICENSE.md feat: add initial project setup 2026-05-21 21:45:36 +02:00
nuget.config feat: add initial project setup 2026-05-21 21:45:36 +02:00
README.md feat: add initial project setup 2026-05-21 21:45:36 +02:00
semver.slnx feat: add initial project setup 2026-05-21 21:45:36 +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);