add function to download and install vsix

This commit is contained in:
Mikhail Timofeev
2020-03-11 14:17:58 +03:00
parent 9bc9285a02
commit 63c8c9c587
4 changed files with 74 additions and 79 deletions

View File

@@ -161,6 +161,74 @@ Hashtable for service arguments
}
}
function Install-VsixExtension
{
Param
(
[String]$Url,
[String]$Name
)
$FilePath = "${env:Temp}\$Name"
$ReleaseInPath = 'Enterprise'
$exitCode = -1
$retries = 20
while($true)
{
try
{
Write-Host "Downloading $Name..."
(New-Object System.Net.WebClient).DownloadFile($Url, $FilePath)
break
}
catch
{
Write-Host "There is an error during $Name downloading"
$_
if ($retries -gt 0)
{
$retries--
Write-Host "Waiting 30 seconds before retrying. Retries left: $retries"
Start-Sleep -Seconds 30
}
else {
Write-Host "File can't be downloaded"
$_
exit 1
}
}
}
$ArgumentList = ('/quiet', $FilePath)
Write-Host "Starting Install $Name..."
try
{
$process = Start-Process -FilePath "C:\Program Files (x86)\Microsoft Visual Studio\2019\$ReleaseInPath\Common7\IDE\VSIXInstaller.exe" -ArgumentList $ArgumentList -Wait -PassThru
}
catch
{
Write-Host "There is an error during $Name installation"
$_
exit 1
}
$exitCode = $process.ExitCode
if ($exitCode -eq 0 -or $exitCode -eq 1001) # 1001 means the extension is already installed
{
Write-Host "$Name installed successfully"
}
else
{
Write-Host "Unsuccessful exit code returned by the installation process: $exitCode."
exit 1
}
#Cleanup installation files
Remove-Item -Force -Confirm:$false $FilePath
}
function Get-VS19ExtensionVersion
{
param (