NuGet.Versioning

Published on Monday, July 21, 2014

NuGet.Versioning is a library for dealing with assembly versions in the strict semantic version format, .NET System.Version w.x.y.z format, and the NuGet hybrid format which is a combination of those.

Version parsing

Semantic Versions

Semantic versions are parsed using a regular expression that contains all of the formatting rules from the SemVer 2.0.0 spec. Leading zeros and empty release labels are not allowed.

^(?<Version>([0-9]|[1-9][0-9]*)(\.([0-9]|[1-9][0-9]*)){2})(?<Release>-([0]\b|[0]$|[0][0-9]*[A-Za-z-]+|[1-9A-Za-z-][0-9A-Za-z-]*)+(\.([0]\b|[0]$|[0][0-9]*[A-Za-z-]+|[1-9A-Za-z-][0-9A-Za-z-]*)+)*)?(?<Metadata>\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$

NuGet Versions

NuGet versions are based on SemVer with support for release labels and build metadata, but it also support the older version formats with one to four numerical parts.

^(?<Version>\d+(\s*\.\s*\d+){0,3})(?<Release>-([0]\b|[0]$|[0][0-9]*[A-Za-z-]+|[1-9A-Za-z-][0-9A-Za-z-]*)+(\.([0]\b|[0]$|[0][0-9]*[A-Za-z-]+|[1-9A-Za-z-][0-9A-Za-z-]*)+)*)?(?<Metadata>\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$

NuGet Package

NuGet.Versioning