Skip to content

Commit a12eb09

Browse files
committed
setup-build: Update VS Installer
1 parent 4665201 commit a12eb09

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

.github/actions/setup-build/action.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ runs:
228228
$InstallerLocation = Join-Path "${env:ProgramFiles(x86)}" "Microsoft Visual Studio" "Installer"
229229
$VSWhere = Join-Path "${InstallerLocation}" "VSWhere.exe"
230230
$VSInstaller = Join-Path "${InstallerLocation}" "vs_installer.exe"
231-
$InstallPath = (& "$VSWhere" -latest -products * -format json | ConvertFrom-Json).installationPath
231+
$VSWhereJSON = (& "$VSWhere" -latest -products * -format json | ConvertFrom-Json)
232+
$InstallPath = $VSWhereJSON.installationPath
233+
$ProductID = $VSWhereJSON.productId
232234
$MSVCDir = Join-Path $InstallPath "VC" "Tools" "MSVC"
233235
234236
# Compute the MSVC version package name from the MSVC version, assuming this is coming from
@@ -243,12 +245,41 @@ runs:
243245
$RevisionVersion = $MinorVersion - 30
244246
$MSVCPackageVersion = "${MajorVersion}.${MinorVersion}.${BuildVersion}.${RevisionVersion}"
245247
248+
# Download the latest VS Installer to update the VS Installer installation. This is needed
249+
# due to a bug in the VS Installer that causes it to fail to self-update. For details, see
250+
# https://developercommunity.visualstudio.com/t/Visual-Studio-Installer-randomly-fails-t/10924708
251+
$VSInstallerURI = switch ($ProductID) {
252+
"Microsoft.VisualStudio.Product.Community" {
253+
"https://aka.ms/vs/17/release/vs_community.exe"
254+
}
255+
"Microsoft.VisualStudio.Product.Enterprise" {
256+
"https://aka.ms/vs/17/release/vs_enterprise.exe"
257+
}
258+
"Microsoft.VisualStudio.Product.Professional" {
259+
"https://aka.ms/vs/17/release/vs_professional.exe"
260+
}
261+
"Microsoft.VisualStudio.Product.BuildTools" {
262+
"https://aka.ms/vs/17/release/vs_buildtools.exe"
263+
}
264+
default {
265+
Write-Output "::error::Unsupported Visual Studio product ID: $ProductID"
266+
exit 1
267+
}
268+
}
269+
$VSProductInstaller = Join-Path "${env:TEMP}" "vs_installer.exe"
270+
Invoke-WebRequest $VSInstallerURI -OutFile $VSProductInstaller -ErrorAction Stop
271+
272+
Write-Output "ℹ️ Updating Visual Studio Installer..."
273+
$process = Start-Process "$VSProductInstaller" `
274+
-PassThru `
275+
-ArgumentList "--update", "--quiet", "--wait"
276+
$process.WaitForExit()
277+
246278
# Install the missing MSVC version.
247279
Write-Output "ℹ️ Installing MSVC packages for ${MSVCPackageVersion}..."
248280
$process = Start-Process "$VSInstaller" `
249281
-PassThru `
250282
-ArgumentList "modify", `
251-
"--noUpdateInstaller", `
252283
"--installPath", "`"$InstallPath`"", `
253284
"--channelId", "https://aka.ms/vs/17/release/channel", `
254285
"--quiet", "--norestart", "--nocache", `

0 commit comments

Comments
 (0)