Amending PowerShell commands in the inline section of provisioners
provisioner "powershell" {
inline = [
# Visual Studio build tools
Write-Host "Installing Visual Studio Build Tools..." -ForegroundColor Cyan
cd $env:USERPROFILE
$exePath = "$env:TEMP\vs_buildtools.exe"
Download the installer
Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_BuildTools.exe -UseBasicParsing -OutFile $exePath
Write-Host "Starting installation with selected components..." -ForegroundColor Cyan
Install the specified workloads
$arguments = @(
"--installPath", "$env:USERPROFILE\vs_BuildTools2022",
"--quiet",
"--norestart",
"--nocache",
"--wait",
"--noUpdateInstaller",
"--noWeb",
"--add", "Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools",
"--add", "Microsoft.VisualStudio.Workload.WebBuildTools",
"--add", "Microsoft.VisualStudio.Workload.AzureBuildTools",
"--add", "Microsoft.VisualStudio.Workload.DataBuildTools",
"--includeRecommended"
)
Start-Process $exePath -ArgumentList $arguments -Wait
Set the environment variable for the path
[Environment]::SetEnvironmentVariable('Path', "$([Environment]::GetEnvironmentVariable('Path', 'Machine'));$env:USERPROFILE\vs_BuildTools2022", 'Machine')
Write-Host "Installation complete." -ForegroundColor Green
]
}
}