diff --git a/eng/common/scripts/Helpers/Package-Helpers.ps1 b/eng/common/scripts/Helpers/Package-Helpers.ps1 index b545872db..ee62c0c4e 100644 --- a/eng/common/scripts/Helpers/Package-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Package-Helpers.ps1 @@ -210,14 +210,33 @@ function Group-ByObjectKey { $groupedDictionary = @{} foreach ($item in $Items) { - $key = Get-ObjectKey $item."$GroupByProperty" + # if the item is an array, we need to group by each element in the array + # however if it's an empty array we want to treat it as a single item + if ($item."$GroupByProperty" -and $item."$GroupByProperty" -is [array]) { + foreach ($GroupByPropertyValue in $item."$GroupByProperty") { + $key = Get-ObjectKey $GroupByPropertyValue - if (-not $groupedDictionary.ContainsKey($key)) { - $groupedDictionary[$key] = @() + if (-not $groupedDictionary.ContainsKey($key)) { + $groupedDictionary[$key] = @() + } + + $groupedDictionary[$key] += $item + } } + else { + if ($item."$GroupByProperty") { + $key = Get-ObjectKey $item."$GroupByProperty" + } + else { + $key = "unset" + } + + if (-not $groupedDictionary.ContainsKey($key)) { + $groupedDictionary[$key] = @() + } - # Add the current item to the array for this key - $groupedDictionary[$key] += $item + $groupedDictionary[$key] += $item + } } return $groupedDictionary