[Windows] Add retry to Install-VsixExtension (#6934)
This commit is contained in:
@@ -274,7 +274,7 @@ function Install-VsixExtension
|
|||||||
[string] $FilePath,
|
[string] $FilePath,
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string] $VSversion,
|
[string] $VSversion,
|
||||||
[int] $retries = 20,
|
[int] $Retries = 20,
|
||||||
[switch] $InstallOnly
|
[switch] $InstallOnly
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -285,45 +285,54 @@ function Install-VsixExtension
|
|||||||
|
|
||||||
$argumentList = ('/quiet', "`"$FilePath`"")
|
$argumentList = ('/quiet', "`"$FilePath`"")
|
||||||
|
|
||||||
Write-Host "Starting Install $Name..."
|
do
|
||||||
$vsEdition = (Get-ToolsetContent).visualStudio.edition
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
$installPath = ${env:ProgramFiles(x86)}
|
Write-Host "Starting Install $Name..."
|
||||||
|
$vsEdition = (Get-ToolsetContent).visualStudio.edition
|
||||||
if (Test-IsWin22)
|
try
|
||||||
{
|
{
|
||||||
$installPath = ${env:ProgramFiles}
|
$installPath = ${env:ProgramFiles(x86)}
|
||||||
|
|
||||||
|
if (Test-IsWin22)
|
||||||
|
{
|
||||||
|
$installPath = ${env:ProgramFiles}
|
||||||
|
}
|
||||||
|
|
||||||
|
#There are 2 types of packages at the moment - exe and vsix
|
||||||
|
if ($Name -match "vsix")
|
||||||
|
{
|
||||||
|
$process = Start-Process -FilePath "${installPath}\Microsoft Visual Studio\${VSversion}\${vsEdition}\Common7\IDE\VSIXInstaller.exe" -ArgumentList $argumentList -Wait -PassThru
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$process = Start-Process -FilePath ${env:Temp}\$Name /Q -Wait -PassThru
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Write-Host "There is an error during $Name installation"
|
||||||
|
$_
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#There are 2 types of packages at the moment - exe and vsix
|
$exitCode = $process.ExitCode
|
||||||
if ($Name -match "vsix")
|
|
||||||
|
if ($exitCode -eq 0 -or $exitCode -eq 1001) # 1001 means the extension is already installed
|
||||||
{
|
{
|
||||||
$process = Start-Process -FilePath "${installPath}\Microsoft Visual Studio\${VSversion}\${vsEdition}\Common7\IDE\VSIXInstaller.exe" -ArgumentList $argumentList -Wait -PassThru
|
Write-Host "$Name installed successfully"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$process = Start-Process -FilePath ${env:Temp}\$Name /Q -Wait -PassThru
|
Write-Host "Unsuccessful exit code returned by the installation process: $exitCode."
|
||||||
|
$Retries--
|
||||||
|
if ($Retries -eq 0) {
|
||||||
|
Write-Host "The $Name couldn't be installed after 20 attempts."
|
||||||
|
}else {
|
||||||
|
Write-Host "Waiting 10 seconds before retrying. Retries left: $Retries"
|
||||||
|
Start-Sleep -Seconds 10
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} until ($exitCode -eq 0 -or $exitCode -eq 1001 -or $Retries -eq 0 )
|
||||||
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 downloaded installation files
|
#Cleanup downloaded installation files
|
||||||
if (-not $InstallOnly)
|
if (-not $InstallOnly)
|
||||||
|
|||||||
Reference in New Issue
Block a user