3

I'm trying to install Visual Studio Build Tools unattended, in PowerShell. I followed https://silentinstallhq.com/visual-studio-build-tools-2022-silent-install-how-to-guide/ and came up with this script:

Write-Host "Installing visual studio build tools..." -ForegroundColor Cyan

$exePath = "$env:TEMP\vs.exe"

Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_BuildTools.exe -UseBasicParsing -OutFile $exePath

Write-Host "layout..." -ForegroundColor Cyan

Start-Process $exePath -ArgumentList "--layout .\vs_BuildTools" -Wait

cd vs_BuildTools

Write-Host "actual installation..." -ForegroundColor Cyan

Start-Process vs_setup.exe -ArgumentList "--installPath $env:USERPROFILE\vs_BuildTools2022 --nocache --wait --noUpdateInstaller --noWeb --allWorkloads --includeRecommended --includeOptional --quiet --norestart" -Wait

however it keeps stuck on layout... for hours. My guesses are that it either is asking for permission or some dialog opens. Is there a way to print what's happening?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • Try this… ```Start-Process -FilePath $exePath -ArgumentList @( “--layout”, “.\vs_BuildTools” ) -Wait``` – mclayton Aug 13 '22 at 07:46
  • @mclayton thanks, please take a look at my update – Guerlando OCs Aug 13 '22 at 15:39
  • You are reinventing the wheels of Chocolatey, https://community.chocolatey.org/packages?q=build+tools+visual+studio – Lex Li Aug 13 '22 at 17:31
  • @LexLi I'm gonna use vcpkg but I need visual studio build tools. – Guerlando OCs Aug 13 '22 at 22:02
  • Your script works for me, perhaps try to put a `cd $env:USERPROFILE` at the beginning to be sur you are in the profile – Christophe Aug 15 '22 at 10:21
  • add a "quiet" argument to avoid "press any key to continue" at the end of download `Start-Process $exePath -ArgumentList "--layout .\vs_BuildTools --quiet" -Wait` – Christophe Aug 15 '22 at 11:30
  • @Christophe problem is that vcpkg cannot locate it: `error: in triplet x64-windows: Unable to find a valid Visual Studio instance`. Is it possibly because of my custom installation location? I tried adding it to the PATH but still same error – Guerlando OCs Aug 15 '22 at 18:51

2 Answers2

1
# Visual Studio build tools
Write-Host "Installing visual studio build tools..." -ForegroundColor Cyan

cd $env:USERPROFILE

$exePath = "$env:TEMP\vs.exe"

Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_BuildTools.exe -UseBasicParsing -OutFile $exePath

Write-Host "layout..." -ForegroundColor Cyan

Start-Process $exePath -ArgumentList "--layout .\vs_BuildTools --quiet" -Wait
cd vs_BuildTools

Write-Host "actual installation..." -ForegroundColor Cyan

Start-Process vs_setup.exe -ArgumentList "--installPath $env:USERPROFILE\vs_BuildTools2022 --nocache --wait --noUpdateInstaller --noWeb --allWorkloads --includeRecommended --includeOptional --quiet --norestart" -Wait

[Environment]::SetEnvironmentVariable('Path', "$([Environment]::GetEnvironmentVariable('Path', 'Machine'));$env:USERPROFILE\vs_BuildTools2022", 'Machine')
Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
0

Before trying to automate the installation, I highly recommend to do it manually at least once. You can just copy the above commands into an interactive PowerShell session and you will see what is going on:

It is just taking ages to install!

And I am not talking about minutes here, but about hours. If you do it interactively, you will see a second console which will print all download steps and display the current progress. You just have to wait a long time until it finishes.

If you want to install it on multiple machines, I recommend to download it only once, serve the layout files (basically your offline installer) on premise and install VS from there.

stackprotector
  • 10,498
  • 4
  • 35
  • 64