103

How to install Visual Studio Code Extensions from Command Prompt while Code Instance is open. I want to install extension from Visual Studio Code gallery.

Following is the extension data i want to install.

enter image description here

My Visual Studio Code Instance is open. What i want to do is to install the following extension from command prompt.

Community
  • 1
  • 1
Shan Khan
  • 9,667
  • 17
  • 61
  • 111
  • Can you not simply open up Visual Studio Code's command palette and type **ext install** and choose John Papa's extension from the extension listing? It appears to be available there now. Why do you wish to do this from a command prompt? – Darren Evans Dec 28 '15 at 19:15
  • 4
    It's probably not to do it manually from the command line just for the fun, but rather to integrate the command in a bigger script that, for instance, sets up his whole system with every of his settings completely automatically. Having to open VS code to do this and click manually defeats the "completely automatically" part – Nicolas Marshall Oct 01 '16 at 16:26
  • @DarrenEvans why do something manually if you can script it? – iconoclast Apr 02 '21 at 23:03

9 Answers9

162

To make it easier to automate and configure VS Code, it is possible to list, install, and uninstall extensions from the command line. When identifying an extension, provide the full name of the form publisher.extension, for example donjayamanne.python.

code --list-extensions
code --install-extension ms-vscode.cpptools
code --uninstall-extension ms-vscode.csharp

Documentation

Shan Khan
  • 9,667
  • 17
  • 61
  • 111
  • 5
    So sad that they did **not** have `--update-extension`. Can't update with command line. – Illuminator Dec 19 '16 at 07:37
  • 2
    code --list-extensions and other commands not work, these commands only open vscode window without doing what is intended to do. btw, i am using vscode win32-x64-1.21.1 on wn7 x64 – hugemeow Mar 30 '18 at 12:30
  • 16
    Updating an extension is now possible using the `--force` option with `--install-extension`. (See GitHub issue [#58434](https://github.com/Microsoft/vscode/issues/58434#issuecomment-421023851), commit [1dd7326](https://github.com/Microsoft/vscode/commit/1dd732608fa588652d4f01aa16e54e8695b0320a).) – Peterino Sep 13 '18 at 20:37
20

According to the documentation, you can use --install-extension for that. For example:

code --install-extension ms-vscode.csharp
svick
  • 236,525
  • 50
  • 385
  • 514
  • 3
    This doesn't work in recent builds. 2 errors are now seen: `Ignoring option install-extension: not supported for code.` and `At least one file or folder must be provided.` – Avindra Goolcharan Jun 01 '20 at 16:58
15

To add to Shan Khan's answer above, if you want to install extensions in a .bat file, you have to use the call keyword, otherwise your script exits after the extension installation completes. Also, if code.exe is not already in the path and you are calling using a full path, make sure you're pointing at the /bin directory:

echo.
echo.
echo Installing VS Code Extensions...
call "C:\Program Files\Microsoft VS Code\bin\code" --install-extension ritwickdey.liveserver
call "C:\Program Files\Microsoft VS Code\bin\code" --install-extension ritwickdey.live-sass
call "C:\Program Files\Microsoft VS Code\bin\code" --install-extension ms-vscode.csharp
call "C:\Program Files\Microsoft VS Code\bin\code" --install-extension PKief.material-icon-theme
echo Done.
echo.
echo.
Aaron Tyler
  • 161
  • 1
  • 2
  • 2
    If you are automating installation of vscode extensions in a script (batch, ansible, bash, etc.) I would recommend adding the `--force` flag, as the `--install-extension` will prompt to update the extension if an old version is already installed. And in an automated script a person will not always be there to answer the prompt. If it is undesirable to always install the latest version of an extension, you will need to use `--list-extensions` and `--show-versions` and programmatically decide whether to update or not. – Kallmanation Oct 17 '18 at 14:28
10

I believe what you want is to install an extension as .vsix file. Documentation here. Copied for reference.

You can manually install an VS Code extension packaged in a .vsix file. Simply install using the VS Code command line providing the path to the .vsix file.

code --install-extension myExtensionFolder\myExtension.vsix

The extension will be installed under your user .vscode/extensions folder. You may provide multiple .vsix files on the command line to install multiple extensions at once.

10762409
  • 523
  • 4
  • 19
Wade Anderson
  • 2,461
  • 1
  • 20
  • 22
  • The senerio you are providing must contain a vsix file. I want to only to give ID or link or name it will download vsix or extension directly from marketplace and install in code. ? – Shan Khan Dec 15 '15 at 16:55
  • Hmm.. I don't see anything in the docs for how to do that. You can use the command pallet as described [here](https://code.visualstudio.com/docs/editor/extension-gallery#_browse-the-gallery-in-vs-code). Is that what you are looking for? If so I'll update my answer. – Wade Anderson Dec 15 '15 at 17:07
  • 4
    In case anyone else runs into this answer. You'll have to use the '--install-extension' parameter to install the vsix. https://code.visualstudio.com/docs/editor/extension-gallery#_install-from-a-vsix – Sorskoot Nov 27 '18 at 15:15
5

The PowerShell script provided by @derekbaker783 didn't worked for me, it throws an exception related that "Code" is not a cmdlet, so I'll share an alternative that worked for me:

$vsCodeExec = ($Env:PROGRAMFILES) + "\Visual Studio Code\Bin\code.cmd"
$extensions = @(
    "ms-vscode.cpptools",               # C/C++ Language Support
    "ms-dotnettools.csharp",            # C# Language Support
    "dbankier.vscode-instant-markdown", # Markdown Language Support
    "ms-vscode.powershell",             # PowerShell Language Support
    "ms-python.python",                 # Python Language Support
    "rebornix.ruby",                    # Ruby Language Support
    "spences10.vba",                    # VBA Language Support
    "luggage66.vbscript",               # VBScript Language Support
    "gordonwalkedby.vbnet",             # VB.NET Language Support
    "dotjoshjohnson.xml",               # XML Language Support
    "abusaidm.html-snippets",           # HTML Snippets
    "ecmel.vscode-html-css",            # CSS Intellisense for HTML
    "formulahendry.code-runner",        # Code Runner
    "ms-vscode-remote.remote-wsl",      # VSCode Remote - WSL
    "vscode-icons-team.vscode-icons",   # Icons for VSCode
    "ms-vscode.vs-keybindings",         # Visual Studio Keymap for VSCode
    "abhiagr.livs"                      # Open/Launch in Visual Studio
) | SORT

$extensions | ForEach-Object {
    try {
        Invoke-Expression "& '$vsCodeExec' --install-extension $_ --force"
        Write-Host # New-Line
    } catch {
        $_
        Exit(1)
    }
}

Exit(0)
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • I think my script didn't work for you because your install is system-wide (rather than per-user) – derekbaker783 May 12 '21 at 02:08
  • 1
    @derekbaker783 I don't have enough knowledge in Powershell to debug and find out the exact cause, but I can say the directory path was not the problem in your script since of course I modified it when trying to use your script to match my current directory path where code.cmd is. But the script was not able to recognize "code" (or "code.cmd") for some reason. I'm using the portable version by the way, no installation at all. Thanks for comment. – ElektroStudios May 13 '21 at 03:10
3

In a Microsoft tutorial "[https://learn.microsoft.com/de-de/azure/azure-signalr/signalr-tutorial-authenticate-azure-functions][1]" they show the following:

func extensions install -p Microsoft.Azure.WebJobs.Extensions.SignalRService -v 1.0.0

but it don't works. So I try a part from here:

code --install-extension Microsoft.Azure.WebJobs.Extensions.SignalRService -v 1.0.0

an got the answer:

1.56.2
054a9295330880ed74ceaedda236253b4f39a335
x64

I hope it will work now...

2

First, find the fully qualified extension name. To do this, you can right-click a given extension, and select 'Copy Extension Id' (while in the extensions pane).

Since the other answers already illustrate .BAT/.CMD syntax, here's an example of installing extensions using a Powershell script (which can of course be executed from CMD).

# A system-wide install of VSCode might be in: "C:\Program Files\Microsoft VS Code\bin\code"
param(
    [string] $pathToVsCodeExe = ($Env:USERPROFILE + '\AppData\Local\Programs\Microsoft VS Code'),
    [string[]] $extensions = @("editorconfig.editorconfig", "dbaeumer.vscode-eslint")
)


try {
    $originalLocation = Get-Location
    Set-Location $pathToVsCodeExe
    $extensions | ForEach-Object {
        Invoke-Expression -Command "Code --install-extension $_ --force"
    }    
}
catch {
    $_
}
finally {
    Set-Location $originalLocation    
}
derekbaker783
  • 8,109
  • 4
  • 36
  • 50
1

To install multiple extensions at the same time, use this format:

code --install-extension dakshmiglani.hex-to-rgba --install-extension dudemelo.php

Benson
  • 4,181
  • 2
  • 26
  • 44
0
#!/bin/bash

# by Cypher
# grab your extensions with:
# codium (or code) --list-extensions --show-versions > codeium.ext
# tweak your extension list to be like the one below
# you can create a $var for "codium --force --install-extension", if you wish...
# https://codeium.com/
# make a bashscript (in GNU/Linux) and easily install them:
# So that the bashscript can be portable for reproducing your config in anoter machine(s)
# save this as, say, "codeiumExtensions.sh"
# chmod +x codeiumExtensions.sh
# then, run it:
# as normal user: ./codeiumExtensions.sh
# codium --help
# --force installs the latest version

codium --force --install-extension  abusaidm.html-snippets@0.2.1
codium --force --install-extension  anilkumarum.compile-ts@0.1.4
codium --force --install-extension  auiworks.amvim@1.36.0
codium --force --install-extension  Codeium.codeium@1.2.36
codium --force --install-extension  dramforever.vscode-ghc-simple@0.2.3
codium --force --install-extension  ecmel.vscode-html-css@1.13.1
codium --force --install-extension  evzen-wybitul.magic-racket@0.6.2
codium --force --install-extension  garrit.p5canvas@1.7.0
codium --force --install-extension  haskell.haskell@2.2.4
codium --force --install-extension  jeandeaual.scheme@0.2.0
codium --force --install-extension  julialang.language-julia@1.47.2
codium --force --install-extension  justusadam.language-haskell@3.6.0
codium --force --install-extension  koog1000.fossil@0.3.1
codium --force --install-extension  ms-python.python@2023.10.1
codium --force --install-extension  ms-vscode.vscode-typescript-next@5.2.20230516
codium --force --install-extension  ocamllabs.ocaml-platform@1.12.2
codium --force --install-extension  rgherdt.scheme-lsp@0.3.12
codium --force --install-extension  ritwickdey.LiveServer@5.7.9
codium --force --install-extension  shaunlebron.vscode-parinfer@0.6.1
codium --force --install-extension  slbtty.Lisp-Syntax@0.2.1
codium --force --install-extension  sumneko.lua@3.6.22
codium --force --install-extension  vscode-org-mode.org-mode@1.0.0
Achylles
  • 31
  • 4