![](/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.