< Back
Compare-SemanticVersion
Post
NAME Compare-SemanticVersion
SYNOPSIS
Compares two semantic version numbers.
SYNTAX
Compare-SemanticVersion [-ReferenceVersion] <Object> [-DifferenceVersion] <Object> [<CommonParameters>]
DESCRIPTION
The Test-SemanticVersion function compares two semantic version numbers and returns an object that contains the
results of the comparison.
PARAMETERS
-ReferenceVersion <Object>
Specifies the version used as a reference for comparison.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-DifferenceVersion <Object>
Specifies the version that is compared to the reference version.
Required? true
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.Object
Any objects you pipe into this function are converted into strings then are evaluated as Semantic Versions.
OUTPUTS
psobject
The output objects are custom psobject with detail of how the ReferenceVersion compares with the
DifferenceVersion
NOTES
To sort a collection of Semantic Version numbers based on the semver.org precedence rules
Sort-Object -Property Major,Minor,Patch,@{e = {$_.PreRelease -eq ''}; Ascending = $true},PreRelease,Build
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '1.1.1' -DifferenceVersion '1.2.0'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
1.1.1 < 1.2.0 True
This command show sthe results of compare two semantic version numbers that are not equal in precedence but are
compatible.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '0.1.1' -DifferenceVersion '0.1.0'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
0.1.1 > 0.1.0 False
This command shows the results of comparing two semantic version numbers that are are not equal in precedence
and are not compatible.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '1.2.3' -DifferenceVersion '1.2.3-0'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
1.2.3 > 1.2.3-0 False
This command shows the results of comparing two semantic version numbers that are are not equal in precedence
and are not compatible.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '1.2.3-4+5' -DifferenceVersion '1.2.3-4+5'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
1.2.3-4+5 = 1.2.3-4+5 True
This command shows the results of comparing two semantic version numbers that are exactly equal in precedence.
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '1.2.3-4+5' -DifferenceVersion '1.2.3-4+6789'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
1.2.3-4+5 = 1.2.3-4+6789 True
This command shows the results of comparing two semantic version numbers that are exactly equal in precedence,
even if they have different build numbers.
RELATED LINKS
SYNOPSIS
Compares two semantic version numbers.
SYNTAX
Compare-SemanticVersion [-ReferenceVersion] <Object> [-DifferenceVersion] <Object> [<CommonParameters>]
DESCRIPTION
The Test-SemanticVersion function compares two semantic version numbers and returns an object that contains the
results of the comparison.
PARAMETERS
-ReferenceVersion <Object>
Specifies the version used as a reference for comparison.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-DifferenceVersion <Object>
Specifies the version that is compared to the reference version.
Required? true
Position? 2
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.Object
Any objects you pipe into this function are converted into strings then are evaluated as Semantic Versions.
OUTPUTS
psobject
The output objects are custom psobject with detail of how the ReferenceVersion compares with the
DifferenceVersion
NOTES
To sort a collection of Semantic Version numbers based on the semver.org precedence rules
Sort-Object -Property Major,Minor,Patch,@{e = {$_.PreRelease -eq ''}; Ascending = $true},PreRelease,Build
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '1.1.1' -DifferenceVersion '1.2.0'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
1.1.1 < 1.2.0 True
This command show sthe results of compare two semantic version numbers that are not equal in precedence but are
compatible.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '0.1.1' -DifferenceVersion '0.1.0'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
0.1.1 > 0.1.0 False
This command shows the results of comparing two semantic version numbers that are are not equal in precedence
and are not compatible.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '1.2.3' -DifferenceVersion '1.2.3-0'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
1.2.3 > 1.2.3-0 False
This command shows the results of comparing two semantic version numbers that are are not equal in precedence
and are not compatible.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '1.2.3-4+5' -DifferenceVersion '1.2.3-4+5'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
1.2.3-4+5 = 1.2.3-4+5 True
This command shows the results of comparing two semantic version numbers that are exactly equal in precedence.
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Compare-SemanticVersion -ReferenceVersion '1.2.3-4+5' -DifferenceVersion '1.2.3-4+6789'
ReferenceVersion Precedence DifferenceVersion IsCompatible
---------------- ---------- ----------------- ------------
1.2.3-4+5 = 1.2.3-4+6789 True
This command shows the results of comparing two semantic version numbers that are exactly equal in precedence,
even if they have different build numbers.
RELATED LINKS