![](/img/trans.png)
[英]Easiest/shortest command to run a PowerShell script as a build event in Visual Studio
[英]Cannot install Visual Studio from PowerShell script
我正在嘗試通過 PowerShell 安裝 Visual Studio,在本地計算機上運行良好,但是當我在我們的 AWS Windows Server 2012R2 上運行它時,我不斷收到錯誤消息。 我在下面附上了我的代碼和錯誤。 謝謝
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$here = pwd
$software = "Microsoft Visual Studio Installer";
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null
#If VSCode was not installed before, it will be download required files and install it.
If(-Not $installed)
{
Write-Host "'$software' is NOT installed.";
wget https://aka.ms/vs/17/release/vs_community.exe -outfile “vs.exe”
.\vs.exe install --quiet --norestart
}
#If VSCode was installed before, it will try to update it to the newer version, if available.
#If no updates available, it will do nothing.
else
{
Write-Host "'$software' is installed."
if ( Test-Path -Path $here\vs.exe )
{
.\vs.exe update --quiet --norestart
}
else {
wget https://aka.ms/vs/17/release/vs_community.exe -outfile "vs.exe"
.\vs.exe update --quiet --norestart
}
}
您使用了選項-outfile vs.exe
但這不是您告訴wget
重命名下載文件的方式。 這實際上是以下內容:
vs_community.exe
(因為這是原始 URL 中的文件名)utfile
vs.exe
參數將下載的內容定向到命名文件的 wget 選項實際上是-O
,而不是-outfile
(相當於-o utfile
,它將日志寫入utfile
)。
要指定正確的輸出文件名,請使用:
-O vs.exe
或者干脆執行wget https://aka.ms/vs/17/release/vs_community.exe
然后執行下載的文件,名為vs_community.exe
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.