Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions scripts/resources/windows/tox/msvc/install_msvc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ function TestInstalledProperty {
Write-Host "Testing for VsDevCmd.bat - Found"

Write-Host "Finished installing Visual Studio Build Tools"


}

function RemoveApplications {
Expand All @@ -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}"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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] `
Expand All @@ -378,4 +403,3 @@ AddStartupScripts `
Write-Host '*************************************************'
Write-Host '* Finished installing Visual Studio Build Tools *'
Write-Host '*************************************************'

Loading