Skip to content
Frank Stüber edited this page Aug 25, 2026 · 8 revisions

Introduction

Enbrea.SemVer is a lightweight .NET implementation of Semantic Versioning 2.0.0 for parsing, validating, comparing, formatting, and working with semantic versions and version ranges.

  • Supports .NET 10, .NET 9, and .NET 8
  • Strict validation of supported SemVer 2.0.0 syntax
  • Parse strings and character spans into strongly typed semantic version objects
  • Full SemVer prerelease precedence support, including alpha, alpha.1, beta.2, and rc.1
  • Support for build metadata such as +build.123, without affecting version precedence
  • Correct comparison of arbitrarily large numeric prerelease identifiers without numeric overflow
  • Implements IComparable<T>, IEquatable<T>, IParsable<T>, and ISpanParsable<T>
  • Parse and evaluate semantic version ranges with inclusive, exclusive, and unbounded endpoints
  • Zero external dependencies

Installation

Install the package from NuGet using the .NET CLI:

dotnet add package Enbrea.SemVer

Or using the Package Manager Console in Visual Studio:

Install-Package Enbrea.SemVer

Or add the package reference directly to your project file:

<ItemGroup>
  <PackageReference Include="Enbrea.SemVer" Version="x.y.z" />
</ItemGroup>

Replace x.y.z with the desired package version.

Quick start

Create a semantic version by parsing its string representation:

using Enbrea.SemVer;

var version = SemanticVersion.Parse("1.2.3-beta.1+build.42");

Console.WriteLine(version.Major);         // 1
Console.WriteLine(version.Minor);         // 2
Console.WriteLine(version.Patch);         // 3
Console.WriteLine(version.PreRelease);    // beta.1
Console.WriteLine(version.BuildMetadata); // build.42
Console.WriteLine(version.IsPrerelease);  // True
Console.WriteLine(version.HasBuildMetadata); // True

Use TryParse when invalid input should not throw an exception:

if (SemanticVersion.TryParse("2.0.0", out var version))
{
    Console.WriteLine(version);
}

Semantic versions can be compared using the standard comparison operators:

var prerelease = SemanticVersion.Parse("2.0.0-rc.1");
var stable = SemanticVersion.Parse("2.0.0");

Console.WriteLine(prerelease < stable); // True

Build metadata does not affect SemVer precedence, but it is considered when testing versions for equality:

var first = SemanticVersion.Parse("1.0.0+build.1");
var second = SemanticVersion.Parse("1.0.0+build.2");

Console.WriteLine(first.HasSamePrecedence(second)); // True
Console.WriteLine(first == second);                 // False

Version ranges can be parsed and used to test whether a version falls within a supported range:

var range = SemanticVersionRange.Parse("[1.0.0,2.0.0)");

Console.WriteLine(range.Satisfies(SemanticVersion.Parse("1.5.0"))); // True
Console.WriteLine(range.Satisfies(SemanticVersion.Parse("2.0.0"))); // False

Using Enbrea.SemVer

Standards

Releases

Clone this wiki locally