How can I install Visual Studio Code extensions offline?

后端 未结 12 1208
终归单人心
终归单人心 2020-11-27 09:12

I have installed Visual Studio Code on a machine that is not, and cannot be, connected to the Internet. According to the documentation, I can install an extension from the c

12条回答
  •  囚心锁ツ
    2020-11-27 10:12

    If you are looking for a scripted solution:

    1. Get binary download URL: you can use an API, but be warned that there is no documentation for it. This API can return an URL to download .vsix files (see example below)
    2. Download the binary
    3. Carefully unzip the binary into ~/.vscode/extensions/: you need to modify unzipped directory name, remove one file and move/rename another one.

    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/node/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": 7 - FilterType.ExtensionName more FilterTypes
    • "flags": 514 - 0x2 | 0x200 - Flags.IncludeFiles | Flags.IncludeLatestVersionOnly - more Flags
      • to get flag decimal value you can run python -c "print(0x2|0x200)"
    • "assetTypes": ["Microsoft.VisualStudio.Services.VSIXPackage"] - to get only link to .vsix file more AssetTypes

提交回复
热议问题