Semver 3.0.0
A Semantic Version Library for .NET
Create, parse, and manipulate semantic version numbers with the SemVersion
class and semantic
version ranges with the SemVersionRange
class. This library complies with v2.0.0 of the semantic
versioning spec from semver.org.
API docs for the most recent release are available online at semver-nuget.org.
Parsing
var version = SemVersion.Parse("1.1.0-rc.1+e471d15", SemVersionStyles.Strict);
Constructing
var v1 = new SemVersion(1, 0);
var vNextRc = SemVersion.ParsedFrom(1, 1, 0, "rc.1");
Comparing
if (version.ComparePrecedenceTo(vNextRc) == 0)
Console.WriteLine($"{version} has the same precedence as {vNextRc}");
if (version.CompareSortOrderTo(vNextRc) > 0)
Console.WriteLine($"{version} sorts after {vNextRc}");
Outputs:
1.1.0-rc.1+e471d15 has the same precedence as 1.1.0-rc.1
1.1.0-rc.1+e471d15 sorts after 1.1.0-rc.1
Manipulating
Console.WriteLine($"Current: {version}");
if (version.IsPrerelease)
{
Console.WriteLine($"Prerelease: {version.Prerelease}");
Console.WriteLine($"Next release version is: {version.WithoutPrereleaseOrMetadata()}");
}
Outputs:
Current: 1.1.0-rc.1+e471d15
Prerelease: rc.1
Next release version is: 1.1.0
Version Ranges
var range = SemVersionRange.Parse("^1.0.0");
var prereleaseRange = SemVersionRange.ParseNpm("^1.0.0", includeAllPrerelease: true);
Console.WriteLine($"Range: {range}");
Console.WriteLine($"Prerelease range: {prereleaseRange}");
Console.WriteLine($"Range includes version {version}: {range.Contains(version)}");
Console.WriteLine($"Prerelease range includes version {version}: {prereleaseRange.Contains(version)}");
// Alternative: another way to call SemVersionRange.Contains(version)
version.Satisfies(range);
// Alternative: slower because it parses the range on every call
version.SatisfiesNpm("^1.0.0", includeAllPrerelease: true)
Outputs:
Range: 1.*
Prerelease range: *-* 1.*
Range includes version 1.1.0-rc.1+e471d15: False
Prerelease range includes version 1.1.0-rc.1+e471d15: True
Showing the top 20 packages that depend on Semver.
Packages | Downloads |
---|---|
DeviceDetector.NET
The Universal Device Detection library for .NET that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, feed readers, media players, PIMs, ...), operating systems, brands and models. This is a port of the popular PHP device-detector library to C#. For the most part you can just follow the documentation for device-detector with no issue.
|
1 |
https://github.com/WalkerCodeRanger/semver/releases/tag/v3.0.0
.NET 5.0
- Microsoft.Extensions.Primitives (>= 5.0.1)
.NET Standard 2.0
- IndexRange (>= 1.0.3)
- Microsoft.Bcl.HashCode (>= 1.1.1)
- Microsoft.Extensions.Primitives (>= 2.0.0)
.NET Standard 2.1
- Microsoft.Extensions.Primitives (>= 3.0.3)
Version | Downloads | Last updated |
---|---|---|
3.0.0 | 1 | 01/20/2025 |
3.0.0-beta.2 | 0 | 09/29/2024 |
3.0.0-beta.1 | 0 | 08/21/2023 |
3.0.0-beta.0 | 0 | 05/07/2023 |
2.3.0 | 0 | 02/21/2023 |
2.3.0-beta.0 | 0 | 12/28/2022 |
2.3.0-alpha.0 | 0 | 07/17/2022 |
2.2.0 | 0 | 06/12/2022 |
2.2.0-rc.0 | 0 | 05/15/2022 |
2.1.0 | 0 | 03/19/2022 |
2.1.0-rc.1 | 0 | 03/19/2022 |
2.1.0-rc.0 | 0 | 03/07/2022 |
2.0.6 | 0 | 12/28/2019 |
2.0.5 | 0 | 10/27/2019 |
2.0.4 | 0 | 08/01/2016 |
2.0.3 | 0 | 07/31/2016 |
1.1.2 | 0 | 05/13/2014 |
1.1.1 | 0 | 11/24/2013 |
1.1.0 | 0 | 11/15/2013 |
1.0.5 | 0 | 07/01/2013 |
1.0.4 | 0 | 07/01/2013 |
1.0.3 | 0 | 01/10/2013 |
1.0.1 | 0 | 01/10/2013 |
1.0.0 | 0 | 01/09/2013 |