[英]How can I install Visual Studio Code extensions offline?
I have installed Visual Studio Code on a machine that is not, and cannot be, connected to the Internet.我在一台没有也不能连接到 Internet 的机器上安装了 Visual Studio Code。 According to the documentation , I can install an extension from the command line if I have the .vsix
, but I don't know how to get the .vsix
from the marketplace. 根据文档,如果我有.vsix
,我可以从命令行安装扩展,但我不知道如何从市场上获取.vsix
。
How can I download the .vsix
for an extension hosted on the marketplace ?我如何为市场上托管的扩展下载.vsix
?
You can now download the extension directly from the marketplace .您现在可以直接从市场下载扩展。
As of Visual Studio Code 1.7.1 dragging or opening the extension does not work any more.从 Visual Studio Code 1.7.1 开始,拖动或打开扩展不再起作用。 In order to install it manually you need to:为了手动安装它,您需要:
According to the documentation it is possible to download an extension directly:根据文档,可以直接下载扩展:
An extension's direct download URL is in the form:扩展程序的直接下载 URL 格式如下:
https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publisher}/extension/${extension name}/${version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage
This means that in order to download the extension you need to know这意味着为了下载扩展你需要知道
You can find all this information in the URL.您可以在 URL 中找到所有这些信息。
Here's an example for downloading an installing the C# v1.3.0 extension:以下是下载安装C# v1.3.0扩展的示例:
You can find the publisher and the extension names on the extension's homepage inside its URL:您可以在扩展程序主页的 URL 中找到发布者和扩展程序名称:
https://marketplace.visualstudio.com/items?itemName= ms-vscode . https://marketplace.visualstudio.com/items?itemName= ms-vscode 。 csharp夏普
Here the publisher is ms-vscode
and the extension name is csharp
.这里发布者是ms-vscode
,扩展名是csharp
。
The version can be found on the right side in the More Info area.该版本可以在“更多信息”区域的右侧找到。
To download it you need to create a link from the template above:要下载它,您需要从上面的模板创建一个链接:
https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-vscode/extension/csharp/1.3.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-vscode/extension/csharp/1.3.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage
All packages will have the same name Microsoft.VisualStudio.Services.VSIXPackage , so you'll need to rename it after downloading if you want to know what package it was later.所有包都将具有相同的名称Microsoft.VisualStudio.Services.VSIXPackage ,因此如果您想知道稍后是哪个包,则需要在下载后重命名它。
In order to install the extension为了安装扩展
*.vsix
extension重命名文件并为其指定*.vsix
扩展名.vsix
file打开 Visual Studio Code,转到菜单File → Open File...或Ctrl + O并选择.vsix
文件Extension was successfully installed.扩展已成功安装。 Restart to enable it.重新启动以启用它。
adding on to t3chb0t's answer, not sure why the option to download is not visible, so created a patch for those who use GreaseMonkey/ TamperMonkey: you can find the gist codehere添加到 t3chb0t 的答案中,不确定为什么下载选项不可见,因此为使用 GreaseMonkey/TamperMonkey 的人创建了一个补丁:您可以在此处找到要点代码
Or you can just paste the below lines in your browser console, and the link would magically appear:或者您可以将以下几行粘贴到您的浏览器控制台中,链接就会神奇地出现:
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);
All these suggestions are great, but kind of painful to follow because executing the code to construct the URL or constructing that crazy URL by hand is kind of annoying...所有这些建议都很棒,但遵循起来有点痛苦,因为执行代码来构造 URL 或手动构造那个疯狂的 URL 有点烦人......
So, I threw together a quick web app to make things easier.所以,我拼凑了一个快速的网络应用程序,让事情变得更容易。 Just paste the URL of the extension you want and out comes out the download of your extension already properly named: publisher-extension-version.vsix.只需粘贴您想要的扩展程序的 URL,您的扩展程序的下载就会正确命名:publisher-extension-version.vsix。
Hope someone finds it helpful: http://vscode-offline.herokuapp.com/希望有人觉得有帮助: http : //vscode-offline.herokuapp.com/
As of today the download URL for the latest version of the extension is embedded verbatim in the source of the page on Marketplace, eg source at URL:截至今天,最新版本扩展程序的下载 URL 已逐字嵌入 Marketplace 页面的源代码中,例如 URL 中的源代码:
https://marketplace.visualstudio.com/items?itemName=lukasz-wronski.ftp-sync
contains string:包含字符串:
https://lukasz-wronski.gallerycdn.vsassets.io/extensions/lukasz-wronski/ftp-sync/0.3.3/1492669004156/Microsoft.VisualStudio.Services.VSIXPackage
I use following Python regexp to extract dl URL:我使用以下 Python regexp 来提取 dl URL:
urlre = re.search(r'source.+(http.+Microsoft\.VisualStudio\.Services\.VSIXPackage)', content)
if urlre:
return urlre.group(1)
I wanted to throw a PowerShell download option on the pile in case anyone else comes across this.我想在文件堆上放一个 PowerShell 下载选项,以防其他人遇到这个问题。 I have several offline scenarios and I run this in a loop to download and update all of the extensions I use offline.我有几个离线场景,我循环运行它以下载和更新我离线使用的所有扩展。
$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"
Adding to t3chb0t's excellent answer - Use these PowerShell commands to install all VSCode extensions in a folder:添加到 t3chb0t 的优秀答案 - 使用这些 PowerShell 命令在文件夹中安装所有 VSCode 扩展:
cd C:\PathToFolderWithManyDownloadedExtensionFiles
Get-ChildItem . -Filter *.vsix | ForEach-Object { code --install-extension $_.FullName }
Then, reload VSCode to complete the installation.然后,重新加载 VSCode 以完成安装。
I've stored a script in my gist to download an extension from the marketplace using a PowerShell script.我在我的 gist 中存储了一个脚本,用于使用 PowerShell 脚本从市场下载扩展。 Feel free to comment of share it.随意评论分享它。
https://gist.github.com/azurekid/ca641c47981cf8074aeaf6218bb9eb58 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"
}
现在您可以直接在“资源”部分下载扩展程序,有一个“下载扩展程序”链接,希望这些信息仍然有用。
If you are looking for a scripted solution:如果您正在寻找脚本化解决方案:
.vsix
files (see example below)这个 API 可以返回一个 URL 来下载.vsix
文件(见下面的例子)unzip
the binary into ~/.vscode/extensions/
: you need to modify unzipped directory name, remove one file and move/rename another one.小心地将二进制文件unzip
到~/.vscode/extensions/
:您需要修改解压缩的目录名称,删除一个文件并移动/重命名另一个文件。For API start by looking at following example, and for hints how to modify request head to https://github.com/Microsoft/vscode/blob/master/src/vs/platform/extensionManagement/common/extensionGalleryService.ts .对于 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,
}
Explanations to the above example:对上述例子的解释:
"filterType": 8
- FilterType.Target
more FilterTypes "filterType": 8
- FilterType.Target
更多 FilterTypes"filterType": 7
- FilterType.ExtensionName
more FilterTypes "filterType": 7
- FilterType.ExtensionName
更多 FilterTypes"flags": 514
- 0x2 | 0x200
"flags": 514
- 0x2 | 0x200
0x2 | 0x200
- Flags.IncludeFiles | Flags.IncludeLatestVersionOnly
0x2 | 0x200
- Flags.IncludeFiles | Flags.IncludeLatestVersionOnly
Flags.IncludeFiles | Flags.IncludeLatestVersionOnly
- more Flags Flags.IncludeFiles | Flags.IncludeLatestVersionOnly
- 更多标志
python -c "print(0x2|0x200)"
要获取标志十进制值,您可以运行python -c "print(0x2|0x200)"
"assetTypes": ["Microsoft.VisualStudio.Services.VSIXPackage"]
- to get only link to .vsix
file more AssetTypes "assetTypes": ["Microsoft.VisualStudio.Services.VSIXPackage"]
- 仅获取指向.vsix
文件的更多 AssetTypes链接If you have a specific (legacy) version of VSCode on your offline instance, pulling the latest extensions might not properly integrate.如果您的离线实例上有特定(旧)版本的 VSCode,则拉取最新扩展可能无法正确集成。
To make sure that VSCode and the extensions work together, they must all be installed together on the online machine.为了确保 VSCode 和扩展一起工作,它们必须一起安装在在线机器上。 This resolves any dependencies (with specific versions), and ensures the exact configuration of the offline instance.这解决了任何依赖关系(具有特定版本),并确保离线实例的准确配置。
Install the VSCode version, turn off updating, and install the extensions.安装VSCode版本,关闭更新,安装扩展。 Copy the extensions from the installed location and place them on the target machine.从安装位置复制扩展并将它们放在目标机器上。
Install the exact version of VSCode on online machine.在在线机器上安装 VSCode 的确切版本。 Then turn off updates by going to File -> Preferences -> Settings
.然后通过转到File -> Preferences -> Settings
关闭更新。 In the Settings
window, under User Settings -> Application
, go to Update
section, and change the parameter for Channel
to none
.在Settings
窗口中,在User Settings -> Application
,转到Update
部分,并将Channel
的参数更改为none
。 This prevents VSCode from reaching out to the internet and auto-updating your versions to the latest.这可以防止 VSCode 连接到 Internet 并将您的版本自动更新到最新版本。
Then go to the VSCode extensions section and install all of your desired extensions.然后转到 VSCode 扩展部分并安装所有所需的扩展。 Copy the installed extensions from their install location (with windows its C:\\Users\\<username>\\.vscode\\extensions
) to the same location on the target machine.将已安装的扩展从其安装位置(Windows 为C:\\Users\\<username>\\.vscode\\extensions
) C:\\Users\\<username>\\.vscode\\extensions
到目标机器上的相同位置。
Works perfectly.完美运行。
For Python users the pattern to use with t3chbot 's excellent answer looks like:对于 Python 用户,与t3chbot的优秀答案一起使用的模式如下所示:
https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-python/vsextensions/python/{version_number}/vspackage
be sure to scroll right to see where you have to enter the version number.请务必向右滚动以查看必须输入版本号的位置。
A small powershell to get needed information for also visual studio extension :一个小的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
}
}
}
}
This use marketplace API to get extension information.这使用市场 API 来获取扩展信息。 Exemple of usage and results :用法和结果示例:
>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
All flags value are available here 此处提供所有标志值
Thanks to m4js7er and Adam Haynes for inspiration感谢 m4js7er 和 Adam Haynes 的启发
Indeed it baffles me that there is no direct curl-friendly URL provided on Marketplace Webpage to download a vscode extension!确实让我感到困惑的是,Marketplace 网页上没有提供直接的 curl 友好 URL 来下载 vscode 扩展! I need that to populate a container in a CICD pipeline.我需要它来填充 CICD 管道中的容器。
I found the answers by @t3chb0t and @LetMeSOThat4U very useful here.我发现@t3chb0t 和@LetMeSOThat4U 的答案在这里非常有用。 In addition, I found that:另外,我发现:
The actual package is either named vspackage or named Microsoft.VisualStudio.Services.VSIXPackage (any others?).实际的包要么命名为 vspackage,要么命名为 Microsoft.VisualStudio.Services.VSIXPackage(还有其他的吗?)。 There is a tag VsixManifestAssetType I think one can use to get the type: "VsixManifestAssetType":"Microsoft.VisualStudio.Services.VsixManifest"有一个标签 VsixManifestAssetType 我认为可以用来获取类型:"VsixManifestAssetType":"Microsoft.VisualStudio.Services.VsixManifest"
These artifacts are tar file.这些工件是 tar 文件。 So if you have download vspackage, to see the content: tar vtf vspackage所以如果你有下载vspackage,看内容:tar vtf vspackage
Now supposedly, an extension jupyter should have .vsix suffix, but none of these packages are named with .vsix.现在据说,扩展 jupyter 应该有 .vsix 后缀,但这些包都没有以 .vsix 命名。 So I think after download, one has to rename the package to .vsix accordingly.所以我认为下载后,必须相应地将包重命名为 .vsix。 With jupyter version 2021.7.0, I'll rename the vspackage to something like: vsx-jupyter-2021.7.0.vsix使用 jupyter 版本 2021.7.0,我会将 vspackage 重命名为:vsx-jupyter-2021.7.0.vsix
On Linux/Ubuntu: I can use the following command to install it: $ code-server --install-extensions vsx-jupyter-2021.7.0.vsix.在 Linux/Ubuntu 上:我可以使用以下命令来安装它:$ code-server --install-extensions vsx-jupyter-2021.7.0.vsix。 Afterward, one can use: code-server --list-extensions to verify.之后,可以使用:code-server --list-extensions 进行验证。
To get the URL of the package ms-python, follow @LetMeSOThat4U method:要获取包 ms-python 的 URL,请遵循 @LetMeSOThat4U 方法:
a. a. Use Chrome browser or curl/wget to get the page https://marketplace.visualstudio.com/items?itemName=ms-python.python使用 Chrome 浏览器或 curl/wget 获取页面https://marketplace.visualstudio.com/items?itemName=ms-python.python
b.湾Right click mouse to select View Page Source and search for string: "AssetUri": You'll see "AssetUri":"https://ms-python.gallerycdn.vsassets.io/extensions/ms-python/python/2021.6.944021595/1623882641726"右键单击鼠标选择查看页面源并搜索字符串:“AssetUri”:您将看到“AssetUri”:“https://ms-python.gallerycdn.vsassets.io/extensions/ms-python/python/2021.6。 944021595/1623882641726"
c. C. Now try to append either vspackage or Microsoft.VisualStudio.Services.VSIXPackage and see which one works.现在尝试附加 vspackage 或 Microsoft.VisualStudio.Services.VSIXPackage 并查看哪个有效。 In this case, it is latter, from the VsixManifestAssetType.在这种情况下,它是后者,来自 VsixManifestAssetType。 So the actual CLI using curl: $ 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所以使用 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 # would show the content of the file $ tar vtf vsx-ms-python-2021.6.vsix # 会显示文件的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.