No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Louis Seubert 95eb4f05a2 fix: make ==/Equals ignore build metadata for precedence
Previously SemanticVersion was a record struct whose ==/Equals/
GetHashCode were synthesized from all fields, so versions that
differ only in build metadata were not equal. Range matching
already used precedence (ignoring metadata), creating an
inconsistency.

Change the type to a plain readonly struct implementing
IEquatable<SemanticVersion> and define ==/Equals/GetHashCode
in terms of SemanticVersionComparer.Priority, so build
metadata is ignored. The custom ToString already existed, so no
display behaviour is lost.

Add a failing-then-passing test.
2026-07-11 23:02:43 +02:00
.forgejo/workflows feat: add initial project setup 2026-05-21 21:45:36 +02:00
src fix: make ==/Equals ignore build metadata for precedence 2026-07-11 23:02:43 +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 fix: make ==/Equals ignore build metadata for precedence 2026-07-11 23:02:43 +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);