diff --git a/scripts/resources/windows/tox/msvc/install_msvc.ps1 b/scripts/resources/windows/tox/msvc/install_msvc.ps1 index 53b816bd..40495183 100644 --- a/scripts/resources/windows/tox/msvc/install_msvc.ps1 +++ b/scripts/resources/windows/tox/msvc/install_msvc.ps1 @@ -133,8 +133,6 @@ function TestInstalledProperty { Write-Host "Testing for VsDevCmd.bat - Found" Write-Host "Finished installing Visual Studio Build Tools" - - } function RemoveApplications { @@ -161,6 +159,8 @@ function InstallMSVC{ [string]$VsInstallPath, [string]$ConfigFile ) + $updateProcesses = @("TiWorker", "TrustedInstaller") + $InstallerFile = "vs_buildtools.exe" Invoke-WebRequest $VsbuildtoolsURL -OutFile $InstallerFile Write-Host "Installing Visual Studio Build Tools to ${VsInstallPath}" @@ -189,11 +189,11 @@ function InstallMSVC{ $resultingConfigFile="c:\setup\myconfig.vsconfig" $exportArgs = @(` 'export', - '--quiet', - '--nocache', - '--force', - '--config', ${resultingConfigFile}, - '--installPath', ${VsInstallPath} + '--quiet', + '--nocache', + '--force', + '--config', ${resultingConfigFile}, + '--installPath', ${VsInstallPath} ) $exportProcess = Start-Process -NoNewWindow -PassThru -FilePath 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe' -ArgumentList $exportArgs -Wait if ( $exportProcess.ExitCode -eq 0) { @@ -239,13 +239,37 @@ function InstallMSVC{ } Write-Host "Cleaning up Package Cache - Done" + Write-Host "Checking for active Windows Update processes..." + + Get-WindowsUpdate + + # Check if any of these processes are actually running right now + $active = Get-Process -Name $updateProcesses -ErrorAction SilentlyContinue + + if ($active) { + $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() + Write-Host "Update in progress. Waiting for completion..." + + # Loop while the processes are still active + while (Get-Process -Name $updateProcesses -ErrorAction SilentlyContinue) { + Get-Process -Name $updateProcesses -ErrorAction SilentlyContinue | Format-Table -AutoSize + Write-Host "Updating..." + + Start-Sleep -Seconds 30 + } + + Write-Host "Windows Update processes have finished." + } else { + Write-Host "No active Windows Update detected. Exiting script." + } + # ======== Wait for Windows Update to finish ======== # It seems that installing MSVC build tools triggers Windows # update. This generates a lot of extra unneeded files for # the docker layer and bloats the image significantly. # Waiting for the update to finish and then cleaning up the # generated files seems to be the best solution to keep the - # layor size down. + # layer size down. $timeout = New-TimeSpan -Hours 1 $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() @@ -339,8 +363,6 @@ function AddStartupScripts{ ) Write-Host "Configuring Visual Studio development environment for shells" - - # ========== Cmd startup ========== Write-Host "Setting up compiler environment to run every time a command is run from CMD" AddVsStudioToCMD -VSInstallPath $VSInstallPath -DevCmdArguments $DevCmdArguments @@ -362,6 +384,9 @@ function AddStartupScripts{ } +Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force +Install-Module PSWindowsUpdate -Force + # ========== Main ========== InstallMSVC ` -VsbuildtoolsURL $VSBUILDTOOLS_URLS[$VSVersion] ` @@ -378,4 +403,3 @@ AddStartupScripts ` Write-Host '*************************************************' Write-Host '* Finished installing Visual Studio Build Tools *' Write-Host '*************************************************' -