11

How can I install multiple extensions in VSCode using the cli? I tried:

code --install-extension xyz.local-history jock.svg

but it only installs the first extension xyz.local-history.

Installing extensions...
Installing extension 'xyz.local-history' v1.7.0...
(node:10874) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Extension 'xyz.local-history' v1.7.0 was successfully installed.
1
  • Can you use a loop in your command line to run code --install-extension multiple times? Commented Oct 23, 2019 at 5:41

10 Answers 10

19

If you are use Unix/Linux create a bash script with a loop. In this case I want to backup the extensions list and install again:

First create a list of the extensions:

$ code --list-extensions > extensions.txt

Create a bash script for example with the name vscode-extension-install.sh and input the following code:

#!/usr/bin/env bash

cat extensions.txt | while read extension || [[ -n $extension ]];
do
  code --install-extension $extension --force
done

Then run:

$ ./vscode-extension-install.sh

Example output:

Installing extensions...
Installing extension 'visualstudioexptteam.vscodeintellicode' v1.2.6...
Extension 'visualstudioexptteam.vscodeintellicode' v1.2.6 was successfully installed.
Installing extensions...
Installing extension 'vscode-icons-team.vscode-icons' v10.0.0...
Extension 'vscode-icons-team.vscode-icons' v10.0.0 was successfully installed.
...

From my gists

Sign up to request clarification or add additional context in comments.

1 Comment

A windows version batch file : <code> @echo off for /F "tokens=*" %%a in (vscode-extensions.txt) do ( code-insiders --install-extension %%a --force ) </code>
8

It's possible to pass the --install-extension argument multiple times and so install several extensions with just one line.

code --install-extension dbaeumer.vscode-eslint --install-extension esbenp.prettier-vscode

The documentation for this can be found in Extension Marketplace. Running this both extensions are installed but Installing extensions... is only found once in the output.

Comments

4

Declare a variable, containing the name of all extensions you want to install... after you have it, you can iterate doing the installation one by one...

for extensions in ms-python.python ms-azure-devops.azure-pipelines ms-mssql.mssql 
do code --install-extension $extensions
done

Maybe you also have to add your code.cmd path, but if your command is working typring code, this will be enough to do the taks Happy coding!

Comments

4

If you are on Windows and do not use WSL, try a PowerShell loop.

  1. Put all desired extensions in a text file (as in Linux example above) - say extensions.txt
  2. Iterate over them with: Get-Content extensions.txt | ForEach-Object {code --install-extension $_}

Note: this would work on every system supporting PowerShell

2 Comments

I wonder how to update the extensions to the latest version, especially extensions inside the extension pack
@Bruce: Using the same switch (--install-extension with a --force argument).
2

there is actually a very simple, one-line solution for this:

$ sed -n 's/^/--install-extension /p' extension.list | xargs code

This will install all extensions exported with code --list-extensions in one call.

1 Comment

This is by far the best answer to the problem
1

Disclaimer: This is not a command line approach, but rather a graphical way to install existing extensions on a new system using .vsix package, and might help some others with the same.


This method to install extensions on a new system (with reference to an existing system) requires Yeoman VS Code extension generator and vsce (or nodejs to install these).

  1. On the existing machine, generate an extension pack (more details here)
npm install -g yo generator-code

yo code

First command installs Yeoman VS Code generator, second creates the extension pack (choose default options as below. The created package.json contains all extensions in the pack, you can modify that list)

enter image description here

enter image description here

enter image description here

  1. On the existing machine, package the extension pack created above into a .vsix file
npm install -g vsce
 
vsce package

First command installs vsce, second packages the extension into a .vsix file (run from the root of the extension pack created above)

enter image description here

  1. On the new system, install the .vsix file
code --install-extension extension-pack-0.0.1.vsix
  1. Open VS Code on the new system, access this extension, install all required extensions via GUI

enter image description here

1 Comment

If you are going to publish the extension pack then consider filling in all details appropriately, while creating it.
1

On Windows:

To export the extensions, run the below PowerShell command on a path where you want to save the file.

code --list-extensions > vscode-extensions.txt 

To import & install the list of extensions in a text file, navigate to the path where the file is located and run the command in PowerShell.

Get-Content vscode-extensions.txt | ForEach-Object { code --install-extension $_ }

where vscode-extensions.txt is the file that contains list of extensions.

Comments

0

CLI find command could support this, in my Dockerfile, code-server could install multi vsix by find command. I think code could use similar scenario

ARG user=docker
#vscode server 1.79.1
ARG vscommit=4cb974a7aed77a74c7813bdccd99ee0d04901215

ADD ./vscode_extension/*.vsix /home/${user}/vscode_extension/
# install vscode extension
RUN find ./ -name '*vsix' -exec  ~/.vscode-server/bin/${vscommit}/bin/code-server --accept-server-license-terms--install-extension {} \;

Comments

0
  1. Create a ./pack/package.json with the minimum required fields

  2. populate your extension codes in extensionPack

  3. be in the ./pack directory, have nodejs installed and run npx vsce package

  4. run code --install-extension ./pack-0.0.1.vsix


I do step 1 once, then step 2 and 3 anytime I want to update my dotfiles setup.

Then I store the vsix file somewhere (like my dotfiles repo) where step 4 can be used when provisioning a dev machine / wsl vm.


minimum required package.json :

{
  "name": "pack",
  "displayName": "pack",
  "version": "0.0.1",
  "engines": {
    "vscode": "*"
  },
  "extensionPack": [
    "ms-azuretools.vscode-docker", 
    "etc"
  ]
}
  • you don't need to publish this
  • you don't need to create an azure account

Comments

-1

Might be useful to others.

I keep a dump of all extensions in text file for example:

code --install-extension aaron-bond.better-comments
code --install-extension abusaidm.html-snippets
code --install-extension afractal.node-essentials
code --install-extension anseki.vscode-color
code --install-extension be5invis.vscode-icontheme-nomo-dark
....

I would copy all contents of text file and then paste all the contents to PowerShell and then it would install plugins one by one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.