StringVersion 1.0.2
dotnet add package StringVersion --version 1.0.2
NuGet\Install-Package StringVersion -Version 1.0.2
<PackageReference Include="StringVersion" Version="1.0.2" />
<PackageVersion Include="StringVersion" Version="1.0.2" />
<PackageReference Include="StringVersion" />
paket add StringVersion --version 1.0.2
#r "nuget: StringVersion, 1.0.2"
#:package StringVersion@1.0.2
#addin nuget:?package=StringVersion&version=1.0.2
#tool nuget:?package=StringVersion&version=1.0.2

StringVersion
A lightweight, high-performance .NET library for parsing and comparing string-based versions, supporting multiple comparison strategies (including SemVer). Features a Span-based tokenizer, custom strategies, and is compatible with a wide range of .NET targets.
Features
- Parse and compare version strings (e.g.,
1.2.3,1.2.3-beta,2023.01.01) - Semantic Versioning (SemVer) comparison out of the box
- Customizable comparison strategies via
IVersionCompareStrategy - Span-based tokenizer for minimal allocations
- Operator overloads for intuitive comparisons (
==,!=,>,<, etc.) - Supports .NET Standard 2.0/2.1, .NET Framework 4.6.2+, .NET 5+, .NET 6+, .NET 7+, .NET 8+, .NET 9, .NET 10
Installation
You can add the package via NuGet (when published):
dotnet add package StringVersion
Usage
Basic Construction & Parsing
using System.StringVersion;
// Construct directly
var v1 = new StringVersion("1.2.3-beta");
// Parse (throws on invalid input)
var v2 = StringVersion.Parse("1.2.3");
// TryParse (safe, returns bool)
if (StringVersion.TryParse("2.0.0-rc1", out var v3))
Console.WriteLine($"Parsed: {v3}");
// ToString
Console.WriteLine(v1.ToString()); // Output: 1.2.3-beta
Comparison
// Operator overloads
if (v1 < v2)
Console.WriteLine($"{v1} is less than {v2}");
if (v1 == v2)
Console.WriteLine("Equal");
// CompareTo
int cmp = v1.CompareTo(v2); // -1, 0, 1
// Equals
bool eq = v1.Equals(v2);
Supported Operators
==,!=<,>,<=,>=
if (v1 >= v2) { /* ... */ }
Semantic Versioning (SemVer)
var semver1 = new StringVersion("1.2.3-alpha.1");
var semver2 = new StringVersion("1.2.3-alpha.2");
Console.WriteLine(semver1 < semver2); // True
Other Comparison Formats
new StringVersion("V1.2.3") > 1; // True
new StringVersion("V1.2.3") > 1L; // True
new StringVersion("V1.2.3") > 1.2d; // True
new StringVersion("V1.2.3") == "1.2.3"; // True
new StringVersion("V1.2.3") == (1, 2, 3); // True
new StringVersion("V1.2.3") == new Version(1, 2, 3); // True
new StringVersion("V1.2.3") == new StringVersion("1.2.3"); // True
Custom Comparison Strategy
Implement IVersionCompareStrategy to define your own comparison logic:
public class MyStrategy : IVersionCompareStrategy
{
public int Compare(ReadOnlySpan<StringToken> x, ReadOnlySpan<StringToken> y)
{
// Custom comparison logic
return x.Length.CompareTo(y.Length); // Example
}
}
// Use custom strategy
var custom = new StringVersion("1.2.3", new MyStrategy());
Advanced Usage
- Supports
IComparable,IEquatable - Can be used as dictionary keys or in sets
- Efficient, allocation-minimizing parsing (Span-based)
- Handles versions with prefixes, suffixes, and various delimiters
// Sorting
var versions = new[] {
new StringVersion("1.0.0"),
new StringVersion("1.0.0-beta"),
new StringVersion("2.0.0")
};
Array.Sort(versions);
// Dictionary usage
var dict = new Dictionary<StringVersion, string>();
dict[new StringVersion("1.0.0")] = "Release 1";
For more details and extension scenarios, see the source code and interface definitions.
Project Structure
src/System.StringVersion/- Main librarysrc/System.StringVersion.Tests/- xUnit test projectsrc/System.StringVersion.Benchmarks/- BenchmarkDotNet performance benchmarks
Build & Test
Run tests:
dotnet test src/System.StringVersion.Tests
Run benchmarks:
dotnet run -c Release --project src/System.StringVersion.Benchmarks
Target Frameworks
- .NET Standard 2.0, 2.1
- .NET Framework 4.6.2, 4.7.2, 4.8, 4.8.1
- .NET 5, 6, 7, 8, 9, 10
License
Repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. 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 is compatible. 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 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. net481 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.7.2
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.8
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.8.1
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.