RamblingCookieMonster / PSDepend

PowerShell Dependency Handler
MIT License
285 stars 76 forks source link

Latest Version is broken if the version goes > 9 because Version is a 'string' #139

Open Miles-Davies-HORIBA opened 1 year ago

Miles-Davies-HORIBA commented 1 year ago

We have a module with version 2.10.0 and PSDepend won't upgrade machines to it because they have the 'latest' version.

You have the latest version of [module-name], with installed version [2.8.0] and PSGallery version [2.10.0]

The issue seems to be the use of the module version, which is a string, in comparisons. Package.ps1 and PSGalleryModule have code similar to

$ExistingVersion = $Existing | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum

where the Measure-Object statement is doing an alpha sort not a 'Version' sort because the Version property is a string type not a Version or more correctly a SemanticVersion type.

This can be fixed by using a calculated property caste to a Version or SemanticVersion

$ExistingVersion = $Existing | Select-Object -Property @{ Name = 'Version' ; Expression = { [Version]$_.Version}} | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum