windows - 如何在无人值守的情况下安装 Visual Studio Build Tools?

标签 windows visual-studio powershell

我正在尝试在 PowerShell 中无人值守地安装 Visual Studio Build Tools。我关注了https://silentinstallhq.com/visual-studio-build-tools-2022-silent-install-how-to-guide/并想出了这个脚本:

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

但是它在 layout... 上停留了几个小时。我的猜测是它要么在请求许可,要么打开了一些对话框。有没有办法打印正在发生的事情?

最佳答案

# 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')

关于windows - 如何在无人值守的情况下安装 Visual Studio Build Tools?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73341154/

相关文章:

powershell - 无法让 Select 命令在 Powershell 中工作

python - pip在Windows上安装geopandas

windows - 从wmic.exe调用中提取感兴趣的行

c - C中的fread错误

IO 完成后的 Windows 线程切换延迟 - 微秒或毫秒

visual-studio - 如何在报表中添加字段(Visual Studio 中的 Crystal Reports)

visual-studio - Visual Studio 边距颜色的含义是什么?

c++ - 在 visual studio 2015 community c++ 中,如何修复警告 C4838 : conversion from 'unsigned int' to 'int' requires a narrowing conversion

powershell - 如何修改cspkg中定义的csdef

PowerShell:获取计算机帐户(不是用户帐户)的成员资格信息