SemVer2.MessagePack 1.0.0

dotnet add package SemVer2.MessagePack --version 1.0.0
                    
NuGet\Install-Package SemVer2.MessagePack -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SemVer2.MessagePack" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SemVer2.MessagePack" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SemVer2.MessagePack" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SemVer2.MessagePack --version 1.0.0
                    
#r "nuget: SemVer2.MessagePack, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SemVer2.MessagePack@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SemVer2.MessagePack&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SemVer2.MessagePack&version=1.0.0
                    
Install as a Cake Tool

SemVer2

Fast C# Implementation of Semantic Versioning 2.0 for .NET

NuGet Releases license

English | 日本語

Overview

SemVer2 is a high-performance Semantic Versioning 2.0 implementation for .NET. It supports modern interfaces such as ISpanFormattable and ISpanParsable<T> and is designed to operate faster than libraries like semver and NuGet.Versioning.

img

Additionally, it includes extensions for System.Text.Json and MessagePack-CSharp and provides a CLI tool available as a .NET Tool.

Installation

NuGet packages

SemVer2 requires .NET Standard 2.1 or later. You can get the package from NuGet.

.NET CLI

dotnet add package SemVer2

Package Manager

Install-Package SemVer2

Usage

You can use the SemVer struct to handle Semantic Versioning.

var semver = SemVer.Create(1, 0, 0, "alpha", "001");
Console.WriteLine(semver);            // 1.0.0-alpha+001
Console.WriteLine(semver.Major);      // 1
Console.WriteLine(semver.Minor);      // 0
Console.WriteLine(semver.Patch);      // 0
Console.WriteLine(semver.Prerelease); // alpha
Console.WriteLine(semver.Build);      // 001

SemVer implements ISpanFormattable, ISpanParsable<T>, IUtf8SpanFormattable, and IUtf8SpanParsable<T>, allowing conversions between UTF-16/UTF-8 strings.

var semver = SemVer.Parse("1.0.0-alpha+001");

Span<char> buffer = stackalloc char[15];
semver.TryFormat(buffer, out var charsWritten);

SemVer also implements IComparable<T> and provides overloaded comparison operators (>, <, >=, <=), enabling version comparisons.

var a = SemVer.Parse("1.0.0");
var b = SemVer.Parse("1.0.1");
var c = SemVer.Parse("1.0.0-alpha");

Console.WriteLine(a < b); // True
Console.WriteLine(a < c); // False

System.Text.Json

SemVer provides SemVerJsonConverter for System.Text.Json. This is included by default in .NET Core 3.0 and later. For .NET Standard 2.1, you can install the SemVer2.SystemTextJson package.

Install-Package SemVer2.SystemTextJson
var options = new JsonSerializerOptions()
{
    Converters =
    {
        new SemVerJsonConverter()
    }
};

JsonSerializer.Serialize(SemVer.Parse("1.0.0"), options);

MessagePack-CSharp

Similarly, SemVerMessagePackFormatter and SemVerMessagePackResolver are provided for MessagePack-CSharp. You can use them by installing the SemVer2.MessagePack package.

Install-Package SemVer2.MessagePack
var resolver = MessagePack.Resolvers.CompositeResolver.Create(
    SemVerMessagePackResolver.Instance,
    MessagePack.Resolvers.StandardResolver.Instance);
var options = MessagePackSerializerOptions.Standard.WithResolver(resolver);

MessagePackSerializer.Serialize(SemVer.Parse("1.0.0"), options);

CLI

SemVer2 provides a .NET Tool that allows you to validate and increment versions via the command line, similar to node-semver.

dotnet tool install --global SemVer2.Cli

You can use it as follows:

$ dotnet semver 1.2.3
1.2.3
$ dotnet semver foo

$ dotnet semver 1.0.0 -i patch
1.0.1

$ dotnet semver 1.0.0,1.0.1,1.0.0-alpha
1.0.0-alpha
1.0.0
1.0.1

Command details are as follows:

Usage: [arguments...] [options...] [-h|--help] [--version]

Prints valid versions sorted by SemVer precedence

Arguments:
  [0] <string[]>

Options:
  -i|--increment <string?>    Increment a version by the specified level. (major | minor | patch | prerelease | release) (Default: null)
  --preid <string?>           Identifier to be used for prerelease version increments. (Default: null)

Performance

Benchmark results are as follows:

Parse (1.2.3)

Method Mean Error StdDev
adamreeve/semver.net 306.70 ns 6.142 ns 5.746 ns
WalkerCodeRanger/semver 186.98 ns 2.114 ns 1.650 ns
Nuget.Versioning 97.16 ns 1.245 ns 0.972 ns
SemVer2 25.85 ns 0.541 ns 1.464 ns

Parse (1.0.0-beta+exp.sha.5114f85)

Method Mean Error StdDev
adamreeve/semver.net 474.64 ns 1.458 ns 1.139 ns
WalkerCodeRanger/semver 363.51 ns 2.213 ns 2.070 ns
Nuget.Versioning 201.76 ns 1.612 ns 1.346 ns
SemVer2 60.53 ns 0.592 ns 0.525 ns

ToString (1.0.0-beta+exp.sha.5114f85)

Method Mean Error StdDev Median
adamreeve/semver.net 194.92 ns 0.915 ns 0.856 ns 195.11 ns
WalkerCodeRanger/semver 67.94 ns 2.613 ns 7.703 ns 63.78 ns
Nuget.Versioning 37.58 ns 0.783 ns 1.599 ns 37.24 ns
SemVer2 20.79 ns 0.166 ns 0.139 ns 20.79 ns

License

This library is released under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 163 3/30/2025
0.1.0 154 3/30/2025