No description
- C# 100%
|
All checks were successful
default / dotnet-default-workflow (push) Successful in 1m4s
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. |
||
|---|---|---|
| .forgejo/workflows | ||
| src | ||
| .editorconfig | ||
| .gitignore | ||
| CHANGELOG.md | ||
| Directory.Build.props | ||
| Directory.Build.targets | ||
| Directory.Packages.props | ||
| global.json | ||
| LICENSE.md | ||
| nuget.config | ||
| README.md | ||
| semver.slnx | ||
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);