How can I install Visual Studio Code extensions offline?

Visual Studio-Code

Visual Studio-Code Problem Overview


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 command line if I have the .vsix, but I don't know how to get the .vsix from the marketplace.

How can I download the .vsix for an extension hosted on the marketplace?

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

UPDATE 2017-12-13

You can now download the extension directly from the marketplace.

Enter image description here

As of Visual Studio Code 1.7.1 dragging or opening the extension does not work any more. In order to install it manually you need to:

  • open the extensions sidebar
  • click on the ellipsis in the right upper corner
  • choose Install from VSIX

Install from VSIX...


Old Method

According to the documentation it is possible to download an extension directly:

> An extension's direct download URL is in the form:

> 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

  • the publisher name
  • the version
  • the extension name

You can find all this information in the URL.

Example

Here's an example for downloading an installing the C# v1.3.0 extension:

Publisher, Extension and Version

You can find the publisher and the extension names on the extension's homepage inside its URL:

> https://marketplace.visualstudio.com/items?itemName=**ms-vscode**.**csharp**

Here the publisher is ms-vscode and the extension name is 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

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.

Installation

In order to install the extension

  • Rename the file and give it the *.vsix extension
  • Open Visual Studio Code, go to menu FileOpen File... or Ctrl + O and select the .vsix file
  • If everything went fine, you should see this message at the top of the window:

> Extension was successfully installed. Restart to enable it.

Solution 2 - Visual Studio-Code

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 code here

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);

Solution 3 - Visual Studio-Code

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...

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.

Hope someone finds it helpful: http://vscode-offline.herokuapp.com/

Solution 4 - Visual Studio-Code

As of today the download URL for the latest version of the extension is embedded verbatim in the source of the page on Marketplace, e.g. source at 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:

urlre = re.search(r'source.+(http.+Microsoft\.VisualStudio\.Services\.VSIXPackage)', content)
if urlre:
    return urlre.group(1)

Solution 5 - Visual Studio-Code

I wanted to throw a PowerShell download option on the pile in case anyone else comes across this. 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"

Solution 6 - Visual Studio-Code

Adding to t3chb0t's excellent answer - Use these PowerShell commands to install all VSCode extensions in a folder:

cd C:\PathToFolderWithManyDownloadedExtensionFiles
Get-ChildItem . -Filter *.vsix | ForEach-Object { code --install-extension $_.FullName }

Then, reload VSCode to complete the installation.

Solution 7 - Visual Studio-Code

If you have a specific (legacy) version of VSCode on your offline instance, pulling the latest extensions might not properly integrate.

To make sure that VSCode and the extensions work together, they must all be installed together on the online machine. This resolves any dependencies (with specific versions), and ensures the exact configuration of the offline instance.

Quick steps:

Install the VSCode version, turn off updating, and install the extensions. Copy the extensions from the installed location and place them on the target machine.

Detailed steps:

Install the exact version of VSCode on online machine. Then turn off updates by going to File -> Preferences -> Settings. In the Settings window, under User Settings -> Application, go to Update section, and change the parameter for Channel to none or Untick Update as shown. This prevents VSCode from reaching out to the internet and auto-updating your versions to the latest.

enter image description here

Then go to the VSCode extensions section and install all of your desired extensions. Copy the installed extensions from their install location (with windows its C:\Users\<username>\.vscode\extensions) to the same location on the target machine.

Works perfectly.

Solution 8 - Visual Studio-Code

I've stored a script in my gist to download an extension from the marketplace using a PowerShell script. Feel free to comment of share it.

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"
}

Solution 9 - Visual Studio-Code

Now you can download an extension directly in the "Resources" section, there's a "Download extension" link, I hope this information is still useful.

Solution 10 - Visual Studio-Code

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/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": 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

Solution 11 - Visual Studio-Code

For Python users the pattern to use with t3chbot's excellent answer looks like:

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.

Solution 12 - Visual Studio-Code

A small powershell to get needed information for also visual studio extension :

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. 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

Solution 13 - Visual Studio-Code

Indeed it baffles me that there is no direct curl-friendly URL provided on Marketplace Webpage to download a vscode extension! I need that to populate a container in a CICD pipeline.

I found the answers by @t3chb0t and @LetMeSOThat4U very useful here. In addition, I found that:

  1. The actual package is either named vspackage or named Microsoft.VisualStudio.Services.VSIXPackage (any others?). There is a tag VsixManifestAssetType I think one can use to get the type: "VsixManifestAssetType":"Microsoft.VisualStudio.Services.VsixManifest"

  2. These artifacts are tar file. So if you have download vspackage, to see the content: tar vtf vspackage

  3. Now supposedly, an extension jupyter should have .vsix suffix, but none of these packages are named with .vsix. So I think after download, one has to rename the package to .vsix accordingly. With jupyter version 2021.7.0, I'll rename the vspackage to something like: vsx-jupyter-2021.7.0.vsix

  4. On Linux/Ubuntu: I can use the following command to install it: $ code-server --install-extensions vsx-jupyter-2021.7.0.vsix. Afterward, one can use: code-server --list-extensions to verify.

  5. To get the URL of the package ms-python, follow @LetMeSOThat4U method:

a. Use Chrome browser or curl/wget to get the page 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"

c. Now try to append either vspackage or Microsoft.VisualStudio.Services.VSIXPackage and see which one works. In this case, it is latter, from the 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

$ tar vtf vsx-ms-python-2021.6.vsix # would show the content of the file

Solution 14 - Visual Studio-Code

From version history tab extension can be downloaded

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionblachnietView Question on Stackoverflow
Solution 1 - Visual Studio-Codet3chb0tView Answer on Stackoverflow
Solution 2 - Visual Studio-CodemidoView Answer on Stackoverflow
Solution 3 - Visual Studio-CodeYaakov ChaikinView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeLetMeSOThat4UView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeAdam HaynesView Answer on Stackoverflow
Solution 6 - Visual Studio-CodeOren ChapoView Answer on Stackoverflow
Solution 7 - Visual Studio-CodepetahView Answer on Stackoverflow
Solution 8 - Visual Studio-CodeAzurekidView Answer on Stackoverflow
Solution 9 - Visual Studio-CodeLuisView Answer on Stackoverflow
Solution 10 - Visual Studio-Codem4js7erView Answer on Stackoverflow
Solution 11 - Visual Studio-CodeLittle Bobby TablesView Answer on Stackoverflow
Solution 12 - Visual Studio-CodeCedricView Answer on Stackoverflow
Solution 13 - Visual Studio-CodeHAltosView Answer on Stackoverflow
Solution 14 - Visual Studio-CodeHisham ShahidView Answer on Stackoverflow