Skip to content

Commit 215e68b

Browse files
authored
setup-build: Update VS Installer (#992)
Due to a bug in the VS installer self-update process, it sometimes fails to properly self-update, preventing the installation of the MSVC packages that we need. In order to work around this issue, we download the newest VS installer for the installed product and run its update process before installing the MSVC packages.
1 parent 4665201 commit 215e68b

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
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", `

.github/workflows/test-setup-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches:
55
- 'main'
66
paths:
7-
- '.github/actions/action.yml'
7+
- '.github/actions/setup-build/action.yml'
88
- '.github/workflows/test-setup-build.yml'
99
workflow_dispatch:
1010
inputs:

0 commit comments

Comments
 (0)