PSSemVer adds a Semantic Versioning 2.0.0 compatible [PSSemVer] class to PowerShell, plus the commands to
create and convert it. Unlike the built-in [version] type, it understands prerelease labels, build metadata, and tag prefixes such
as v1.2.3, and it compares versions using the precedence rules from the SemVer specification.
Install the module from the PowerShell Gallery:
Install-PSResource -Name PSSemVer
Import-Module -Name PSSemVerParse a version from a string, including prerelease, build metadata, and a tag prefix:
$version = New-PSSemVer -Version 'v1.2.3-alpha.1+001'
$version.Prefix # v
$version.Major # 1
$version.Prerelease # alpha.1
$version.BuildMetadata # 001Compare versions using SemVer precedence, so prereleases sort before their release:
[PSSemVer]'1.0.0-beta.2' -lt [PSSemVer]'1.0.0-beta.11' # True
[PSSemVer]'1.0.0-rc.1' -lt [PSSemVer]'1.0.0' # TrueBump a version in place, including the prerelease counter:
$version = New-PSSemVer -Version '1.2.3'
$version.BumpMinor() # 1.3.0
$version.SetPrerelease('alpha') # 1.3.0-alpha
$version.BumpPrereleaseNumber() # 1.3.0-alpha.1Convert values coming off the pipeline and sort them by SemVer precedence:
'1.0.0', '0.9.0', '1.0.0-rc.1' | ConvertTo-PSSemVer | Sort-Object
# 0.9.0
# 1.0.0-rc.1
# 1.0.0Documentation is published at psmodule.io/PSSemVer.
Use PowerShell help and command discovery for module details:
Get-Command -Module PSSemVer
Get-Help -Name New-PSSemVer -Examples