@@ -228,7 +228,9 @@ runs:
228
228
$InstallerLocation = Join-Path "${env:ProgramFiles(x86)}" "Microsoft Visual Studio" "Installer"
229
229
$VSWhere = Join-Path "${InstallerLocation}" "VSWhere.exe"
230
230
$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
232
234
$MSVCDir = Join-Path $InstallPath "VC" "Tools" "MSVC"
233
235
234
236
# Compute the MSVC version package name from the MSVC version, assuming this is coming from
@@ -243,12 +245,41 @@ runs:
243
245
$RevisionVersion = $MinorVersion - 30
244
246
$MSVCPackageVersion = "${MajorVersion}.${MinorVersion}.${BuildVersion}.${RevisionVersion}"
245
247
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
+
246
278
# Install the missing MSVC version.
247
279
Write-Output "ℹ️ Installing MSVC packages for ${MSVCPackageVersion}..."
248
280
$process = Start-Process "$VSInstaller" `
249
281
-PassThru `
250
282
-ArgumentList "modify", `
251
- "--noUpdateInstaller", `
252
283
"--installPath", "`"$InstallPath`"", `
253
284
"--channelId", "https://aka.ms/vs/17/release/channel", `
254
285
"--quiet", "--norestart", "--nocache", `
0 commit comments