@@ -327,20 +327,43 @@ jobs:
327327 ref : ${{ inputs.ref || '' }}
328328
329329 - name : Select Xcode matching the pinned workload band
330+ shell : pwsh
330331 run : |
331- band=$(sed -n 's:.*<MacTargetPlatformVersion>\(.*\)</MacTargetPlatformVersion>.*:\1:p' Directory.Build.props | tr -d '[:space:]')
332- if [ -z "$band" ]; then
333- echo "ERROR: could not read MacTargetPlatformVersion from Directory.Build.props."
332+ [xml]$props = Get-Content -Raw Directory.Build.props
333+ $band = $props.SelectSingleNode("//MacTargetPlatformVersion")?.InnerText?.Trim()
334+ if ([string]::IsNullOrWhiteSpace($band)) {
335+ Write-Error "Could not read MacTargetPlatformVersion from Directory.Build.props."
334336 exit 1
335- fi
336- xc=$(ls -d /Applications/Xcode_${band}*.app 2>/dev/null | sort -V | tail -1 || true)
337- if [ -z "$xc" ]; then
338- ls -d /Applications/Xcode* 2>/dev/null || true
339- echo "ERROR: the .NET macOS workload band $band requires a matching Xcode bundle; none found."
337+ }
338+
339+ # Bundle names differ by installer (Xcode_26.0.1.app on hosted images,
340+ # Xcode-26.0.1.app from xcodes), so match the version a bundle reports,
341+ # not its name. Highest patch within the band wins.
342+ $bandMatches = @()
343+ $found = @()
344+ foreach ($app in @(Get-ChildItem -LiteralPath '/Applications' -Directory -Filter 'Xcode*.app' -ErrorAction SilentlyContinue)) {
345+ $xcodebuild = Join-Path $app.FullName 'Contents/Developer/usr/bin/xcodebuild'
346+ if (-not (Test-Path -LiteralPath $xcodebuild)) { continue }
347+ $report = & $xcodebuild -version 2>$null | Out-String
348+ if ($report -notmatch 'Xcode\s+([\d.]+)') { continue }
349+ $version = $Matches[1]
350+ $found += "$($app.FullName) -> Xcode $version"
351+ $majorMinor = ($version.TrimEnd('.') -split '\.')[0..1] -join '.'
352+ if ($majorMinor -eq $band) {
353+ $bandMatches += [pscustomobject]@{ Version = $version; Path = $app.FullName }
354+ }
355+ }
356+
357+ if ($bandMatches.Count -eq 0) {
358+ Write-Host ($found -join [Environment]::NewLine)
359+ Get-ChildItem -LiteralPath '/Applications' -Filter 'Xcode*' -ErrorAction SilentlyContinue | ForEach-Object { Write-Host $_.Name }
360+ Write-Error "No installed Xcode reports version $band.x."
340361 exit 1
341- fi
342- echo "DEVELOPER_DIR=$xc/Contents/Developer" >> "$GITHUB_ENV"
343- "$xc/Contents/Developer/usr/bin/xcodebuild" -version
362+ }
363+
364+ $xc = ($bandMatches | Sort-Object { [version]$_.Version } | Select-Object -Last 1).Path
365+ "DEVELOPER_DIR=$xc/Contents/Developer" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
366+ & (Join-Path $xc 'Contents/Developer/usr/bin/xcodebuild') -version
344367
345368 - name : Setup .NET
346369 uses : ./.github/actions/setup-dotnet
0 commit comments