From a11787a2993e948b941bae4a02d94083ab6be507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bere=C5=BCa=C5=84ski?= Date: Wed, 2 May 2018 21:59:08 +0200 Subject: [PATCH] chocolatey-visualstudio.extension: work around broken --update feature of the bootstrapper Due to the way the VS Installer update feature of the VS setup bootstrapper (--update) is implemented, --update must be the last argument, otherwise the bootstrapper will assume it is in "roundtrip update" mode and will start the VS Installer once it is updated. The problem is that recent versions of the parent ("box") application (vs_.exe) started appending an additional argument (--env) to the VS setup bootstrapper invocation, effectively breaking the --update feature. To add insult to injury, the --env argument is not used during the VS installer update. Fortunately, the box application is just a flavor of a self-extracting zip archive and can be unzipped using standard zip tools. So, the workaround is to unzip the box application and invoke the extracted VS setup bootstrapper, taking care to pass arguments in correct order. GitHub-Issue: GH-7 GH-8 GH-26 --- .../extensions/Install-VSInstaller.ps1 | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/chocolatey-visualstudio.extension/extensions/Install-VSInstaller.ps1 b/chocolatey-visualstudio.extension/extensions/Install-VSInstaller.ps1 index 566018be..374c0ec6 100644 --- a/chocolatey-visualstudio.extension/extensions/Install-VSInstaller.ps1 +++ b/chocolatey-visualstudio.extension/extensions/Install-VSInstaller.ps1 @@ -123,6 +123,34 @@ function Install-VSInstaller } } + $boxExe = Get-VSWebFile ` + -PackageName 'Visual Studio Installer' ` + -DefaultFileName 'vs_setup.exe' ` + -FileDescription 'installer executable' ` + -Url $Url ` + -Checksum $Checksum ` + -ChecksumType $ChecksumType ` + -LocalFilePath $installerFilePath + + $chocTempDir = $env:TEMP + $tempDir = Join-Path $chocTempDir "$PackageName" + if ($env:packageVersion -ne $null) { $tempDir = Join-Path $tempDir "$env:packageVersion" } + + $extractedBoxPath = Join-Path -Path $tempDir -ChildPath (Get-Item -Path $boxExe).BaseName + if (Test-Path -Path $extractedBoxPath) + { + Write-Debug "Removing already existing box extraction path: $extractedBoxPath" + Remove-Item -Path $extractedBoxPath -Recurse + } + + Get-ChocolateyUnzip ` + -PackageName 'Visual Studio Installer' ` + -FileFullPath $boxExe ` + -Destination $extractedBoxPath ` + | Out-Null + + $vsSetupBootstrapperExe = Join-Path -Resolve -Path $extractedBoxPath -ChildPath 'vs_bootstrapper_d15\vs_setup_bootstrapper.exe' + $whitelist = @('quiet', 'offline') Remove-VSPackageParametersNotPassedToNativeInstaller -PackageParameters $PackageParameters -TargetDescription 'bootstrapper during VS Installer update' -Whitelist $whitelist @@ -132,12 +160,9 @@ function Install-VSInstaller $arguments = @{ packageName = 'Visual Studio Installer' silentArgs = $silentArgs - url = $Url - checksum = $Checksum - checksumType = $ChecksumType + file = $vsSetupBootstrapperExe logFilePath = $null assumeNewVS2017Installer = $true - installerFilePath = $installerFilePath } $argumentsDump = ($arguments.GetEnumerator() | ForEach-Object { '-{0}:''{1}''' -f $_.Key,"$($_.Value)" }) -join ' ' @@ -146,8 +171,8 @@ function Install-VSInstaller { $retry = $false $attempt += 1 - Write-Debug "Install-VSChocolateyPackage $argumentsDump" - Install-VSChocolateyPackage @arguments + Write-Debug "Install-VSChocolateyInstallPackage $argumentsDump" + Install-VSChocolateyInstallPackage @arguments $updated = Get-VisualStudioInstaller if ($updated -eq $null)