-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisual-studio-extension-install.ps1
47 lines (36 loc) · 1.46 KB
/
visual-studio-extension-install.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Install-VSIXExtension {
param (
[Parameter(Mandatory = $true)]
[string]
$itemName,
[Parameter(Mandatory = $true)]
[string]
$displayName
)
$ErrorActionPreference = "Stop"
$baseHostName = "marketplace.visualstudio.com"
$uri = "https://$($baseHostName)/items?itemName=$($itemName)"
$vsixLocation = "$($env:Temp)\$([guid]::NewGuid()).vsix"
$vsInstallerServicePath = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service"
if (-Not $vsInstallerServicePath) {
Write-Error "Visual Studio Installer Service is missing"
Exit 1
}
$html = Invoke-WebRequest -Uri $uri -UseBasicParsing -SessionVariable session
$anchor = $html.Links |
Where-Object { $_.class -eq 'install-button-container' } |
Select-Object -ExpandProperty href
if (-Not $anchor) {
Write-Error "Could not find download anchor tag on the Visual Studio Extensions page for the extension $($displayName)"
Exit 1
}
$href = "https://$($baseHostName)$($anchor)"
Invoke-WebRequest $href -OutFile $vsixLocation -WebSession $session
if (-Not (Test-Path $vsixLocation)) {
Write-Error "Downloaded VSIX file could not be located for the extension $($displayName)"
Exit 1
}
Write-Host "Installing $($displayName)"
Start-Process -Filepath "$($vsInstallerServicePath)\VSIXInstaller" -ArgumentList "/q /a $($vsixLocation)" -Wait
Remove-Item $vsixLocation
}