0

按名称安装扩展一文描述了如何按名称从市场安装扩展。

是否也可以在本地将扩展安装到 Azure DevOps 服务器?

  1. 步:server_ip/_gallery/manage

  2. 步骤:上传

在此处输入图像描述

  1. 步骤:安装

在此处输入图像描述

以编程方式完成这些步骤会很棒。

4

2 回答 2

2

用于将基于.vsix文件的扩展添加或删除到 Azure DevOps 服务器扩展库的 PowerShell 脚本:

$PAT = "PersonalAccessToken"
$Uri = "http://ip:port"
$timeout = 30

#AUTHORIZATION HEADERS
$headers = @{
    "Authorization" = ('Basic {0}' -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)")))
    "If-Match"      = ""
}

#VARIABLE
$publisher = "YourPublisherName"
$extension = "YourExtensionName"
$vsix = "YourVsixPath.vsix"

#DELETE EXTENSION
$api = "api-version=5.0-preview.2"
$url = "$Uri/_apis/gallery/publishers/$publisher/extensions/$($extension)?$api"
$result = Invoke-RestMethod -Uri $url -Method DELETE -ContentType "application/json" -Headers $headers -TimeoutSec $timeout -Verbose
Write-Host $result

#ADD EXTENSION
$api = "api-version=3.0-preview.1"
$body = '{{"extensionManifest": "{0}"}}' -f ([Convert]::ToBase64String([IO.File]::ReadAllBytes($vsix)))
$url = "$Uri/_apis/gallery/extensions?$api"
$result = Invoke-RestMethod -Uri $url -Method POST -ContentType "application/json" -Headers $headers -Body $body -TimeoutSec $timeout -Verbose
Write-Host $result
于 2019-08-15T11:59:13.037 回答
1

根据文档,Azure DevOps Server 2019(甚至 TFS 2018)也支持这个 Rest API:

https://{instance}/{collection}/_apis/extensionmanagement/installedextensionsbyname/{publisherName}/{extensionName}/{version}?api-version=5.0-preview.1
于 2019-08-13T06:24:26.053 回答