无需下载 VSIX 即可确定 Visual Studio Code 扩展兼容性

问题描述 投票:0回答:1

我需要为 VScode IDE 构建一个离线设置,其中包含一些 Python 所需的 VScode 扩展包。我可以使用的 VScode IDE 的唯一可用版本是 1.77.3,因此这不是这里的变量(好吧,它可能是,但现在不是)。

所以,简单的问题是:是否有某种方法可以使用 vsce(或其他便利工具)不仅查询可供下载的 VSIX 包的版本,而且还可以获取每个版本兼容的 VScode 版本无需下载 VSIX 包本身??

我有一组 python 方法,当给定 {publisher}.{package} 格式的 VScode 扩展名称和 VScode 版本时,它们将尝试找出最新的兼容 VSIX 包版本。它很慢,因为我知道提取兼容性信息的唯一方法是下载所有可能的 VSIX 包版本(使用 vsce 提取),然后循环遍历所有版本,解压缩并提取 package.json 信息以获取最小版本“engines/vscode”字段中兼容的 VScode 版本。

这种方法的问题是,对于一些更频繁更新的扩展包,有无数个版本,我必须将每个版本下载到临时目录中,解析它,将其吹走,等等......这需要尽管它有效,但完成的时间确实很长。

visual-studio-code versioning offline vsix
1个回答
0
投票

在撰写本文时,似乎最终已通过此 merge 添加了 feature request,但在发行版中尚未提供。为了使用新功能,我直接从存储库安装了它:

git clone https://github.com/microsoft/vscode-vsce.git
cd vscode-vsce/ 
npm install -g

我使用

show
标志和 vscode 的 python 扩展测试了该命令,下面的输出显示了版本 2022.14.0 的内容。

        {
            "version": "2022.14.0",
            "flags": 1,
            "lastUpdated": "2022-09-01T19:26:37.230Z",
            "properties": [
                {
                    "key": "Microsoft.VisualStudio.Services.Branding.Color",
                    "value": "#1e415e"
                },
                {
                    "key": "Microsoft.VisualStudio.Services.Branding.Theme",
                    "value": "dark"
                },
                {
                    "key": "Microsoft.VisualStudio.Services.Links.Getstarted",
                    "value": "https://github.com/Microsoft/vscode-python.git"
                },
                {
                    "key": "Microsoft.VisualStudio.Services.Links.Support",
                    "value": "https://github.com/Microsoft/vscode-python/issues"
                },
                {
                    "key": "Microsoft.VisualStudio.Services.Links.Learn",
                    "value": "https://github.com/Microsoft/vscode-python"
                },
                {
                    "key": "Microsoft.VisualStudio.Services.Links.Source",
                    "value": "https://github.com/Microsoft/vscode-python.git"
                },
                {
                    "key": "Microsoft.VisualStudio.Services.Links.GitHub",
                    "value": "https://github.com/Microsoft/vscode-python.git"
                },
                {
                    "key": "Microsoft.VisualStudio.Code.Engine",
                    "value": "^1.68.0"
                },
                {
                    "key": "Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown",
                    "value": "true"
                },
                {
                    "key": "Microsoft.VisualStudio.Code.ExtensionDependencies",
                    "value": ""
                },
                {
                    "key": "Microsoft.VisualStudio.Services.CustomerQnALink",
                    "value": "https://github.com/microsoft/vscode-python/discussions/categories/q-a"
                },
                {
                    "key": "Microsoft.VisualStudio.Code.ExtensionPack",
                    "value": "ms-toolsai.jupyter,ms-python.vscode-pylance"
                },
                {
                    "key": "Microsoft.VisualStudio.Code.LocalizedLanguages",
                    "value": ""
                },
                {
                    "key": "Microsoft.VisualStudio.Code.ExtensionKind",
                    "value": "workspace,web"
                }
            ]
        },

在属性字段中,您现在可以查看与列表中的 Microsoft.VisualStudio.Code.Engine key

 关联的 value 中列出的每个版本的兼容 Visual Studio Code 版本。下面是一个受 repo 启发的示例,它使用 python vscode 扩展的目标版本的版本来解析 json 输出(2022.14.0 是仍然与 python3.6 still 兼容的任意版本) :
import subprocess
import json


extension = "ms-python.python"
target_extension_version = "2022.14.0"
command = f"vsce show {extension} --json"
output = subprocess.check_output(command, shell=True)
data = json.loads(output)
target_extension_version_info = [version for version in data["versions"] if version["version"] == target_extension_version ][0]
compatible_vscode = [info for info in target_extension_version_info["properties"] if info["key"] == "Microsoft.VisualStudio.Code.Engine"][0]["value"]
print(f"Compatibile VS Code for the extension {extension} with version {target_extension_version} is : {compatible_vscode} ")

输出:

Compatibile VS Code for the extension ms-python.python with version 2022.14.0 is : ^1.68.0

© www.soinside.com 2019 - 2024. All rights reserved.