{"id":38193370,"url":"https://github.com/droidsolutions/semantic-version","last_synced_at":"2026-01-17T00:17:29.374Z","repository":{"id":38198766,"uuid":"451882831","full_name":"droidsolutions/semantic-version","owner":"droidsolutions","description":"NuGet package with tools for comparing Semantic Version numbers","archived":false,"fork":false,"pushed_at":"2025-12-16T10:06:43.000Z","size":1704,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-18T13:27:46.478Z","etag":null,"topics":["nuget","nuget-package","semantic","semantic-version","version","versioning"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/droidsolutions.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-01-25T13:12:50.000Z","updated_at":"2025-12-16T10:06:41.000Z","dependencies_parsed_at":"2023-12-25T10:44:15.342Z","dependency_job_id":"21405621-6d25-4921-be43-9e322a865d7d","html_url":"https://github.com/droidsolutions/semantic-version","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/droidsolutions/semantic-version","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/droidsolutions%2Fsemantic-version","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/droidsolutions%2Fsemantic-version/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/droidsolutions%2Fsemantic-version/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/droidsolutions%2Fsemantic-version/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/droidsolutions","download_url":"https://codeload.github.com/droidsolutions/semantic-version/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/droidsolutions%2Fsemantic-version/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28490046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T23:55:29.509Z","status":"ssl_error","status_checked_at":"2026-01-16T23:55:29.108Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nuget","nuget-package","semantic","semantic-version","version","versioning"],"created_at":"2026-01-17T00:17:25.963Z","updated_at":"2026-01-17T00:17:29.340Z","avatar_url":"https://github.com/droidsolutions.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DroidSolutions Semantic Version\n\nThis is a NuGet package containing a library that provides sort and compare functions for [Semantic Version](https://semver.org/) numbers.\n\n[![Coverage Status](https://coveralls.io/repos/github/droidsolutions/semantic-version/badge.svg?branch=main)](https://coveralls.io/github/droidsolutions/semantic-version?branch=main)\n![Nuget](https://img.shields.io/nuget/v/DroidSolutions.Oss.SemanticVersion)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\n# Installation\n\nYou can install this package via CLI: `dotnet add package DroidSolutions.Oss.SemanticVersion`.\n\nIf you want to install it in a project that is in a subdirectory give the path to the directory containing the `csproj` file or the path to the `csproj` like this: `dotnet add src/MyProject package DroidSolutions.Oss.SemanticVersion`.\n\n# Usage\n\n## ISemanticVersion\n\nThere is an interface `ISemanticVersion` for which comparers are implemented. Just create a class and implement the interface.\n\n## SemanticVersionObject\n\nYou can also use the `SemanticVersionObject` class that already implements the comparer with some neat and handy additions.\n\nAdditionally `SemanticVersionObject` provides a `Build` property containing any build metadata. As per [specification](https://semver.org/#spec-item-10) build metadtaa data may only contain ASCII alphanumerics and hyphens `[0-9A-Za-z-]` and can be appended at the end of the version with a plus sign `+`.\n\n### Constructor\n\nWhen you create a new `SemanticVersionObject` instance you can give the version number parts straight away.\n\n```csharp\nSemanticVersionObject version = new();                   // 1.0.0\nSemanticVersionObject version = new(2);                  // 2.0.0\nSemanticVersionObject version = new(1, 1);               // 1.1.0\nSemanticVersionObject version = new(1, 1, 1);            // 1.1.1\nSemanticVersionObject version = new(1, 1, 1, \"alpha.1\"); // 1.1.1-alpha.1\nSemanticVersionObject version = new(1, 1, 1, \"alpha.1\", \"298a915a\"); // 1.1.1-alpha.1+298a915a\nSemanticVersionObject version = new(1, 1, 1, null, \"298a915a\"); // 1.1.1+298a915a\n```\n\n### FromString\n\nThere is also a static `FromString` Method which will return you a `SemanticVersionObject` instance from a version string.\n\n```csharp\nvar version = SemanticVersionObject.FromString(\"v1.0.0-beta.1+298a915a985daeb426a0fe7543917874d7fa2995\");\n```\n\n### FromVersion\n\nThere is a static method to take the version from a .NET `Version` instance called `FromVersion`. It takes the `Version` instance as a parameter.\n\nThe second parameter controls how build and revision are used. [The Version docs](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-version) state, that revision should be used for assemblies that fix security holes but are otherwise the same. This would match the sense of the `Patch` part of semantic version, so this is the default, setting the `Revision` property to the patch version.\n\nHowever when using the `Version` build property in `.csproj` the generated version in `AssemblyInfo.cs` ends up in a way where patch version lands in the build property instead of revision. So when using the method with an Assembly version, you can pass `true` to the method and the patch version will be read from the `Build` property and `Revision` is used for build version.\n\n## GetCurrentAppVersion\n\nThis retrieves the version from the current running application and returns a `SemanticVersionObject` for it. For this `Assembly.GetEntryAssembly()` is used.\n\n### ToString\n\nYou can generate a version string with the `ToString` method:\n\n```csharp\nSemanticVersionObject version = new() { Major = 1, Minor = 2, Patch = 3, PreRelease = \"beta.1\", Build = \"298a915a\" };\nConsole.WriteLine(version.ToString()); // v1.2.3-beta.1+298a915a\n```\n\nIf you do not want the leading `v` you can use the `ToVersionString` method and give false for the `withLeadingV` parameter:\n\n```csharp\nvar version = new SemanticVersionObject { Major = 1, Minor = 4, Patch = 0 };\nConsole.WriteLine(version.ToVersionString(false)); // 1.4.0\n```\n\n### Sorting\n\nAs mentioned a default comparer is included which allows to sort version descending to have the newest version first. You can use the `Sort` LinQ method for this:\n\n```csharp\nList\u003cSemanticVersionObject\u003e list = new()\n{\n  SemanticVersionObject.FromString(\"1.0.0\"),\n  SemanticVersionObject.FromString(\"1.1.1\"),\n  SemanticVersionObject.FromString(\"1.1.0\"),\n  SemanticVersionObject.FromString(\"0.9.0\"),\n};\n\nlist.Sort();\n\nAssert.Equal(\n  new List\u003cSemanticVersionObject\u003e\n  {\n    SemanticVersionObject.FromString(\"1.1.1\"),\n    SemanticVersionObject.FromString(\"1.1.0\"),\n    SemanticVersionObject.FromString(\"1.0.0\"),\n    SemanticVersionObject.FromString(\"0.9.0\"),\n  },\n  list);\n```\n\nYou can also use the Array `Sort` method but then you have to specify the compare method yourself:\n\n```csharp\nvar list = new SemanticVersionObject[]\n{\n  SemanticVersionObject.FromString(\"1.0.0\"),\n  SemanticVersionObject.FromString(\"1.1.1\"),\n  SemanticVersionObject.FromString(\"1.1.0\"),\n  SemanticVersionObject.FromString(\"0.9.0\"),\n};\n\nArray.Sort(list, SemanticVersionObject.SortVersionDescending());\n\nAssert.Equal(\n  new List\u003cSemanticVersionObject\u003e\n  {\n    SemanticVersionObject.FromString(\"1.1.1\"),\n    SemanticVersionObject.FromString(\"1.1.0\"),\n    SemanticVersionObject.FromString(\"1.0.0\"),\n    SemanticVersionObject.FromString(\"0.9.0\"),\n  },\n  list);\n```\n\n### Compare\n\nThe `SemanticVersionObject` class implements the `IComparable` interface so you can use the `CompareTo` on every instance. Just pass another instance to it. The result is an integer that tells you, if the given instance is newer (1), equal (0) or older (-1).\n\n```csharp\nSemanticVersionObject oldVersion = new(1, 0, 0);\nSemanticVersionObject equalVersion = new(1, 0, 0);\nSemanticVersionObject newVersion = new(1, 1, 0);\n\nConsole.WriteLine(oldVersion.CompareTo(newVersion)); // 1\nConsole.WriteLine(newVersion.CompareTo(oldVersion)); // -1\nConsole.WriteLine(oldVersion.CompareTo(equalVersion)); // 0\n```\n\n### General notes on sorting and comparing\n\nSorting (and comparing) takes into account if there is a prerelease or not. For example consider this:\n\n```csharp\nSemanticVersionObject x = new(1, 0, 0);\nSemanticVersionObject y = new(1, 0, 0, \"alpha.1\");\n\nConsole.WriteLine(x.CompareTo(y)); // -1\n```\n\nVersion without a prerelease are always newer if major, minor and patch are equal.\n\nAlso consider this:\n\n```csharp\nSemanticVersionObject x = new(1, 0, 0, \"beta.2\");\nSemanticVersionObject y = new(1, 0, 0, \"beta.10\");\n\nConsole.WriteLine(x.CompareTo(y)); // 1\n```\n\nPrereleases will be split into their parts and then will be compared. Each part must be separated with a dot. So for example beta is higher than alpha but just because b is later in the alphabet than a.\n\n```csharp\nSemanticVersionObject x = new(1, 0, 0, \"alpha.1\");\nSemanticVersionObject y = new(1, 0, 0, \"beta.1\");\nSemanticVersionObject z = new(1, 0, 0, \"develop.1\");\n\nConsole.WriteLine(x.CompareTo(y)); // 1\nConsole.WriteLine(y.CompareTo(z)); // 1\n```\n\nAs per [spec](https://semver.org/#spec-item-10) build metadata is ignored when comparing.\n\n```csharp\nList\u003cSemanticVersionObject\u003e list = new()\n{\n  SemanticVersionObject.FromString(\"1.0.0+200\"),\n  SemanticVersionObject.FromString(\"1.0.0+100\"),\n};\n\nlist.Sort();\n\nAssert.Equal(\n  new List\u003cSemanticVersionObject\u003e\n  {\n    SemanticVersionObject.FromString(\"1.0.0+200\"),\n    SemanticVersionObject.FromString(\"1.0.0+100\"),\n  },\n  list);\n```\n\n### IsNewerThan, IsOlderThan\n\nYou can use the `IsNewerThan` or `IsOlderThan` method if you need a boolean value.\n\n```csharp\nvar x = new SemanticVersionObject(2, 0, 0);\nvar y = new SemanticVersionObject(1, 0, 0);\n\nvar isNewer = x.IsNewerThan(y); // true\nvar isolder = y.IsOlderThan(x); // true\n```\n\nThe methods only return `true` if the given instance is newer/older. If they are both the same or the given compare version is null `false` is returned.\n\n### IsPreRelease\n\nYou can use the `IsPreRelease` method to determine if the given version is a pre release or a full semantic version.\n\n```csharp\nSemanticVersionObject.FromString(\"v2.0.3\").IsPreRelease(); // false\nSemanticVersionObject.FromString(\"3.1.3-beta.12\").IsPreRelease(); // true\n```\n\n# Development\n\nIf you want to add a feature or fix a bug, be sure to read the [contribution guidelines](./CONTRIBUTING.md) first.\n\nYou'll need to install the .NET SDK which can be downloaded [here](https://dotnet.microsoft.com/en-us/download).\n\nTo build the project, just run `dotnet build` in the repository root. Tests can be executed with `dotnet test` and code coverage is generated by either running `dotnet test --collect:\"XPlat Code Coverage\"` or `dotnet test /p:CollectCoverage=true`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdroidsolutions%2Fsemantic-version","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdroidsolutions%2Fsemantic-version","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdroidsolutions%2Fsemantic-version/lists"}