[英]How can I install Visual Studio Code extensions offline?
您現在可以直接從市場下載擴展。
從 Visual Studio Code 1.7.1 開始,拖動或打開擴展不再起作用。 為了手動安裝它,您需要:
根據文檔,可以直接下載擴展:
擴展程序的直接下載 URL 格式如下:
https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publisher}/extension/${extension name}/${version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage
這意味着為了下載擴展你需要知道
您可以在 URL 中找到所有這些信息。
以下是下載安裝C# v1.3.0擴展的示例:
您可以在擴展程序主頁的 URL 中找到發布者和擴展程序名稱:
https://marketplace.visualstudio.com/items?itemName= ms-vscode 。 夏普
這里發布者是ms-vscode
,擴展名是csharp
。
該版本可以在“更多信息”區域的右側找到。
要下載它,您需要從上面的模板創建一個鏈接:
所有包都將具有相同的名稱Microsoft.VisualStudio.Services.VSIXPackage ,因此如果您想知道稍后是哪個包,則需要在下載后重命名它。
為了安裝擴展
*.vsix
擴展名.vsix
文件擴展已成功安裝。 重新啟動以啟用它。
添加到 t3chb0t 的答案中,不確定為什么下載選項不可見,因此為使用 GreaseMonkey/TamperMonkey 的人創建了一個補丁:您可以在此處找到要點代碼
或者您可以將以下幾行粘貼到您的瀏覽器控制台中,鏈接就會神奇地出現:
let version = document.querySelector('.ux-table-metadata > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > div:nth-child(1)').innerText
, itemDetails = window.location.search.replace('?', '').split('&').filter(str => !str.indexOf('itemName')).map(str => str.split('=')[1])[0]
, [author, extension] = itemDetails.split('.')
, lAuthor = author.toLowerCase()
, href = `https://${lAuthor}.gallery.vsassets.io:443/_apis/public/gallery/publisher/${author}/extension/${extension}/${version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage`
, element = document.createElement('a');
element.href = href;
element.className = 'vscode-moreinformation dark';
element.innerHTML = 'download .vsix file';
element.download = `${extension}.${version}.vsix`;
document.querySelector('.vscode-install-info-container').appendChild(element);
所有這些建議都很棒,但遵循起來有點痛苦,因為執行代碼來構造 URL 或手動構造那個瘋狂的 URL 有點煩人......
所以,我拼湊了一個快速的網絡應用程序,讓事情變得更容易。 只需粘貼您想要的擴展程序的 URL,您的擴展程序的下載就會正確命名:publisher-extension-version.vsix。
希望有人覺得有幫助: http : //vscode-offline.herokuapp.com/
截至今天,最新版本擴展程序的下載 URL 已逐字嵌入 Marketplace 頁面的源代碼中,例如 URL 中的源代碼:
https://marketplace.visualstudio.com/items?itemName=lukasz-wronski.ftp-sync
包含字符串:
https://lukasz-wronski.gallerycdn.vsassets.io/extensions/lukasz-wronski/ftp-sync/0.3.3/1492669004156/Microsoft.VisualStudio.Services.VSIXPackage
我使用以下 Python regexp 來提取 dl URL:
urlre = re.search(r'source.+(http.+Microsoft\.VisualStudio\.Services\.VSIXPackage)', content)
if urlre:
return urlre.group(1)
我想在文件堆上放一個 PowerShell 下載選項,以防其他人遇到這個問題。 我有幾個離線場景,我循環運行它以下載和更新我離線使用的所有擴展。
$page = Invoke-WebRequest -Uri 'https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell'
$details = ( $page.Scripts | ? {$_.class -eq 'vss-extension'}).innerHTML | Convertfrom-Json
$extensionName = $details.extensionName
$publisher = $details.publisher.publisherName
$version = $details.versions.version
Invoke-WebRequest -uri "$($details.versions.fallbackAssetUri)/Microsoft.VisualStudio.Services.VSIXPackage" `
-OutFile "C:\Scripts\extensions\$publisher.$extensionName.$version.VSIX"
添加到 t3chb0t 的優秀答案 - 使用這些 PowerShell 命令在文件夾中安裝所有 VSCode 擴展:
cd C:\PathToFolderWithManyDownloadedExtensionFiles
Get-ChildItem . -Filter *.vsix | ForEach-Object { code --install-extension $_.FullName }
然后,重新加載 VSCode 以完成安裝。
我在我的 gist 中存儲了一個腳本,用於使用 PowerShell 腳本從市場下載擴展。 隨意評論分享它。
https://gist.github.com/azurekid/ca641c47981cf8074aeaf6218bb9eb58
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string] $Publisher,
[Parameter(Mandatory = $true)]
[string] $ExtensionName,
[Parameter(Mandatory = $true)]
[ValidateScript( {
If ($_ -match "^([0-9].[0-9].[0-9])") {
$True
}
else {
Throw "$_ is not a valid version number. Version can only contain digits"
}
})]
[string] $Version,
[Parameter(Mandatory = $true)]
[string] $OutputLocation
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
Write-Output "Publisher: $($Publisher)"
Write-Output "Extension name: $($ExtensionName)"
Write-Output "Version: $($Version)"
Write-Output "Output location $($OutputLocation)"
$baseUrl = "https://$($Publisher).gallery.vsassets.io/_apis/public/gallery/publisher/$($Publisher)/extension/$($ExtensionName)/$($Version)/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
$outputFile = "$($Publisher)-$($ExtensionName)-$($Version).visx"
if (Test-Path $OutputLocation) {
try {
Write-Output "Retrieving extension..."
[uri]::EscapeUriString($baseUrl) | Out-Null
Invoke-WebRequest -Uri $baseUrl -OutFile "$OutputLocation\$outputFile"
}
catch {
Write-Error "Unable to find the extension in the marketplace"
}
}
else {
Write-Output "The Path $($OutputLocation) does not exist"
}
現在您可以直接在“資源”部分下載擴展程序,有一個“下載擴展程序”鏈接,希望這些信息仍然有用。
如果您正在尋找腳本化解決方案:
.vsix
文件(見下面的例子)unzip
到~/.vscode/extensions/
:您需要修改解壓縮的目錄名稱,刪除一個文件並移動/重命名另一個文件。對於 API,請查看以下示例,並了解如何將請求頭修改為https://github.com/Microsoft/vscode/blob/master/src/vs/platform/extensionManagement/common/extensionGalleryService.ts 的提示。
POST https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery?api-version=5.1-preview HTTP/1.1
content-type: application/json
{
"filters": [
{
"criteria": [
{
"filterType": 8,
"value": "Microsoft.VisualStudio.Code",
},
{
"filterType": 7,
"value": "ms-python.python",
}
],
"pageNumber": 1,
"pageSize": 10,
"sortBy": 0,
"sortOrder": 0,
}
],
"assetTypes": ["Microsoft.VisualStudio.Services.VSIXPackage"],
"flags": 514,
}
對上述例子的解釋:
"filterType": 8
- FilterType.Target
更多 FilterTypes"filterType": 7
- FilterType.ExtensionName
更多 FilterTypes"flags": 514
- 0x2 | 0x200
0x2 | 0x200
- Flags.IncludeFiles | Flags.IncludeLatestVersionOnly
Flags.IncludeFiles | Flags.IncludeLatestVersionOnly
- 更多標志
python -c "print(0x2|0x200)"
"assetTypes": ["Microsoft.VisualStudio.Services.VSIXPackage"]
- 僅獲取指向.vsix
文件的更多 AssetTypes鏈接如果您的離線實例上有特定(舊)版本的 VSCode,則拉取最新擴展可能無法正確集成。
為了確保 VSCode 和擴展一起工作,它們必須一起安裝在在線機器上。 這解決了任何依賴關系(具有特定版本),並確保離線實例的准確配置。
安裝VSCode版本,關閉更新,安裝擴展。 從安裝位置復制擴展並將它們放在目標機器上。
在在線機器上安裝 VSCode 的確切版本。 然后通過轉到File -> Preferences -> Settings
關閉更新。 在Settings
窗口中,在User Settings -> Application
,轉到Update
部分,並將Channel
的參數更改為none
。 這可以防止 VSCode 連接到 Internet 並將您的版本自動更新到最新版本。
然后轉到 VSCode 擴展部分並安裝所有所需的擴展。 將已安裝的擴展從其安裝位置(Windows 為C:\\Users\\<username>\\.vscode\\extensions
) C:\\Users\\<username>\\.vscode\\extensions
到目標機器上的相同位置。
完美運行。
對於 Python 用戶,與t3chbot的優秀答案一起使用的模式如下所示:
https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-python/vsextensions/python/{version_number}/vspackage
請務必向右滾動以查看必須輸入版本號的位置。
一個小的powershell,用於獲取visual studio擴展所需的信息:
function Get-VSMarketPlaceExtension {
[CmdLetBinding()]
Param(
[Parameter(ValueFromPipeline = $true,Mandatory = $true)]
[string[]]
$extensionName
)
begin {
$body=@{
filters = ,@{
criteria =,@{
filterType=7
value = $null
}
}
flags = 1712
}
}
process {
foreach($Extension in $extensionName) {
$response = try {
$body.filters[0].criteria[0].value = $Extension
$Query = $body|ConvertTo-JSON -Depth 4
(Invoke-WebRequest -Uri "https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery?api-version=6.0-preview" -ErrorAction Stop -Body $Query -Method Post -ContentType "application/json")
} catch [System.Net.WebException] {
Write-Verbose "An exception was caught: $($_.Exception.Message)"
$_.Exception.Response
}
$statusCodeInt = [int]$response.StatusCode
if ($statusCodeInt -ge 400) {
Write-Warning "Erreur sur l'appel d'API : $($response.StatusDescription)"
return
}
$ObjResults = ($response.Content | ConvertFrom-Json).results
If ($ObjResults.resultMetadata.metadataItems.count -ne 1) {
Write-Warning "l'extension '$Extension' n'a pas été trouvée."
return
}
$Extension = $ObjResults.extensions
$obj2Download = ($Extension.versions[0].properties | Where-Object key -eq 'Microsoft.VisualStudio.Services.Payload.FileName').value
[PSCustomObject]@{
displayName = $Extension.displayName
extensionId = $Extension.extensionId
deploymentType = ($obj2Download -split '\.')[-1]
version = [version]$Extension.versions[0].version
LastUpdate = [datetime]$Extension.versions[0].lastUpdated
IsValidated = ($Extension.versions[0].flags -eq "validated")
extensionName = $Extension.extensionName
publisher = $Extension.publisher.publisherName
SourceURL = $Extension.versions[0].assetUri +"/" + $obj2Download
FileName = $obj2Download
}
}
}
}
這使用市場 API 來獲取擴展信息。 用法和結果示例:
>Get-VSMarketPlaceExtension "ProBITools.MicrosoftReportProjectsforVisualStudio"
displayName : Microsoft Reporting Services Projects
extensionId : 85e42f76-6afa-4a68-afb5-033d1fe08d7b
deploymentType : vsix
version : 2.6.7
LastUpdate : 13/05/2020 22:23:45
IsValidated : True
extensionName : MicrosoftReportProjectsforVisualStudio
publisher : ProBITools
SourceURL : https://probitools.gallery.vsassets.io/_apis/public/gallery/publisher/ProBITools/extension/MicrosoftReportProjectsforVisualStudio/2.6.7/assetbyname/Microsoft.DataTools.ReportingServices.vsix
FileName : Microsoft.DataTools.ReportingServices.vsix
此處提供所有標志值
感謝 m4js7er 和 Adam Haynes 的啟發
確實讓我感到困惑的是,Marketplace 網頁上沒有提供直接的 curl 友好 URL 來下載 vscode 擴展! 我需要它來填充 CICD 管道中的容器。
我發現@t3chb0t 和@LetMeSOThat4U 的答案在這里非常有用。 另外,我發現:
實際的包要么命名為 vspackage,要么命名為 Microsoft.VisualStudio.Services.VSIXPackage(還有其他的嗎?)。 有一個標簽 VsixManifestAssetType 我認為可以用來獲取類型:"VsixManifestAssetType":"Microsoft.VisualStudio.Services.VsixManifest"
這些工件是 tar 文件。 所以如果你有下載vspackage,看內容:tar vtf vspackage
現在據說,擴展 jupyter 應該有 .vsix 后綴,但這些包都沒有以 .vsix 命名。 所以我認為下載后,必須相應地將包重命名為 .vsix。 使用 jupyter 版本 2021.7.0,我會將 vspackage 重命名為:vsx-jupyter-2021.7.0.vsix
在 Linux/Ubuntu 上:我可以使用以下命令來安裝它:$ code-server --install-extensions vsx-jupyter-2021.7.0.vsix。 之后,可以使用:code-server --list-extensions 進行驗證。
要獲取包 ms-python 的 URL,請遵循 @LetMeSOThat4U 方法:
a. 使用 Chrome 瀏覽器或 curl/wget 獲取頁面https://marketplace.visualstudio.com/items?itemName=ms-python.python
灣右鍵單擊鼠標選擇查看頁面源並搜索字符串:“AssetUri”:您將看到“AssetUri”:“https://ms-python.gallerycdn.vsassets.io/extensions/ms-python/python/2021.6。 944021595/1623882641726"
C. 現在嘗試附加 vspackage 或 Microsoft.VisualStudio.Services.VSIXPackage 並查看哪個有效。 在這種情況下,它是后者,來自 VsixManifestAssetType。 所以使用 curl 的實際 CLI: $ curl -o vsx-ms-python-2021.6.vsix --insecure https://ms-python.gallerycdn.vsassets.io/extensions/ms-python/python/2021.6.944021595/1623882641726 /Microsoft.VisualStudio.Services.VSIXPackage
$ tar vtf vsx-ms-python-2021.6.vsix # 會顯示文件的內容
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.