param([string]$SdkVersion, [string[]]$ExtensionNames, [bool]$AllowPrerelease, [ref]$Extensions) function Get-BestVersion { param([string[]] $versions) $sdkMatch = [Regex]::Match($SdkVersion, '^(?<1>\d+)\.(?<2>\d+)') $sdkMajor = [int]::Parse($sdkMatch.Groups[1].Value) $sdkMinor = [int]::Parse($sdkMatch.Groups[2].Value) $bestMajor = 0 $bestMinor = 0 $bestRevision = 0 foreach($v in $versions) { $m = [Regex]::Match($v, '^(?<1>\d+)\.(?<2>\d+)\.(?<3>\d+)$') if($m.Success) { $major = [int]::Parse($m.Groups[1].Value) $minor = [int]::Parse($m.Groups[2].Value) if($major -le $sdkMajor -and $minor -le $sdkMinor) { $revision = [int]::Parse($m.Groups[3].Value) if($major -gt $bestMajor) { $bestMajor = $major $bestMinor = $minor $bestRevision = $revision } elseif($major -eq $bestMajor -and $minor -gt $bestMinor) { $bestMajor = $major $bestMinor = $minor $bestRevision = $revision } elseif($major -eq $bestMajor -and $minor -eq $bestMinor -and $revision -gt $bestRevision) { $bestMajor = $major $bestMinor = $minor $bestRevision = $revision } } } } return [string]::Format('{0}.{1}.{2}', $bestMajor, $bestMinor, $bestRevision) } $myExtensions = @{} Write-Output 'Getting list of extensions...' foreach($ext in (Invoke-WebRequest -Uri https://proget.inedo.com/upack/PrereleaseExtensions/Packages -UseBasicParsing | ConvertFrom-Json)) { if($ext.name -iin $ExtensionNames) { if($AllowPrerelease) { $myExtensions.Add($ext.name, $ext.latestVersion) } else { $myExtensions.Add($ext.name, (Get-BestVersion -versions $ext.versions)) } } } $Extensions = $myExtensions
Close