If you have multiple developers w/ multiple developer workstations and they each have VS Code, how can I track what extensions that have from a central location? I don't want to have to sign on to each workstation one at a time and pull up VS Code for a list of installed extensions and versions. FOr example, there is a vulnerability in VS Code's TS-Lint extension. How can I tell what computers in my group have that installed?
Method 1: Query the File System
The Common Questions section of the page Managing Extensions in Visual Studio Code shows where extensions are installed:
Where are extensions installed?
Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder:
Windows: %USERPROFILE%\.vscode\extensions
macOS: ~/.vscode/extensions
Linux: ~/.vscode/extensions
The extensions directory contains one subdirectory for each installed extension, named like (extension)-(version). Listing its contents for each user and machine should provide a comprehensive list of installed extensions.
Method 2: Query VSCode Itself
Another approach is to use the VSCode command line as explained in the Command Line Extension Management of that same page. In particular, you can run:
$ ./bin/code --list-extensions --show-versions
from the VSCode install directory when logged in as a particular user to get a list of (extension)#(version) strings.
But note: you have to use the code program in the bin subdirectory of VSCode, which is a shell script (requiring Cygwin on Windows). On Windows at least, there is also Code.exe in the top-level VSCode directory, but that one does not respect those command line flags.
Related
I've put Visual Studio Code on OneDrive, for the purpose of syncing it with its settings across my devices.
However, extensions are stored in %USERPROFILE%\.vscode\extensions on Windows.
Is it possible to change this folder's location so I can put it in the main Visual Studio Code folder?
At first I thought that copying the extensions in the resources\app\extensions of Visual Studio Code folder will be a nice workaround, but that doesn't work.
I've also searched for a solution on the documentation page and in the user settings, with no results.
What I did - after installing Visual Studio Code for the first time, I checked the documentation and added at the end of 'Target' field of editor's shortcut the following (there's a space before the two dashes):
--extensions-dir="DRIVELETTER:\VSCODE\extensions"
--user-data-dir="DRIVELETTER:\VSCODE\settings"
where DRIVERLETTER and VSCODE are the corresponding drive and directory where Visual Studio Code is installed. So mine looks like this:
"D:\Microsoft VS Code\Code.exe" --extensions-dir="D:\Microsoft VS Code\extensions"
Here is for the user data directory:
"D:\Microsoft VS Code\Code.exe" --user-data-dir="D:\Microsoft VS Code\settings"
Accessing the 'Target' field is done by right-clicking the shortcut and choosing 'Properties'
Anyway, there's a simpler solution to that problem - just use the portable version of Visual Studio Code. It works under Windows, Linux, and macOS:
Enable Portable Mode
Windows and Linux
After unzipping the Visual Studio Code download, simply create a data folder within Visual Studio Code's folder:
|- VSCode-win32-x64-1.25.0-insider
| |- Code.exe (or code executable)
| |- data
| |- ...
From then on, that folder will be used to contain all Visual Studio Code data, including session state, preferences, extensions, etc.
The data folder can be moved to other Visual Studio Code installations. This is useful for updating your portable Visual Studio Code version: simply move the data folder to a newer extracted version of Visual Studio Code.
macOS
On macOS, you need to place the data folder as a sibling of the application itself. Since the folder will be alongside the application, you need to name it specifically so that Code can find it. The default folder name is code-portable-data:
|- Visual Studio Code.app
|- code-portable-data
Portable mode won't work if your application is in quarantine, which happens by default if you just downloaded Visual Studio Code. Make sure you remove the quarantine attribute, if portable mode doesn't seem to work:
xattr -dr com.apple.quarantine Visual\ Studio\ Code.app
Note: On Insiders, the folder should be named code-insiders-portable-data.
UPDATE 14.12.2021
From Visual Studio Docs
Note: Do not attempt to configure portable mode on an installation from the Windows User or System installers. Portable mode is only supported on the Windows ZIP (.zip) archive. Note as well that the Windows ZIP archive does not support auto update.
A little hack:
Create a symbolic link to the folder %USERPROFILE%\.vscode\extensions under the Visual Studio Code install path.
https://code.visualstudio.com/docs/editor/extension-gallery
code --extensions-dir 'new_directory_to_set'
Set the root path for extensions.
Follow the below steps for changing the extension path in VS.
Set "code" path in environment variable.
path = VS_CODE_INSTALL_DIRECTORY/bin;
Open VS , in VS terminal execute the below command.
code --extensions-dir "new_directory_path"
Install the required extension.
All Done.
Note:Dont forget to vote the answer
According to this page, after installing VS Code we should make a language profilers folder like this:
mkdir code_profiles
cd code_profiles
mkdir code-ruby
cd code-ruby
mkdir exts
mkdir data
For Windows, I prepared a batch file (.bat) for each language I work on, it contains this line:
Start "" "D:\programs\VSCode\code.exe" --extensions-dir D:\programs\VSCode\code_profiles\code-python\exts --user-data-dir D:\programs\VSCode\code_profiles\code-python\data .
This is for Python. If I work on PHP, I will make code-php folder, then make exts and data folders in it and prepare another batch file for PHP, just like the one I made for python.
I put this batch file on the main project folder then double click on it to run VS Code with the preferred profile.
I use VS Code as my main code editor for my C++ development. I am using the remote SSH extension by Microsoft to access my office workstation from home. For the C++ autocompletion and linting I use the clangd extension by LLVM. Company policy prevents users from having sudo access to workstations and libraries are often not at the latest version.
When I try to launch clangd I get the following error message:
/lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /my/path/to/clangd)
Which obviously means that the version of libstdc++ is too old for the version of clangd that I am using. This is easily fixable by adding to LD_LIBRARY_PATH the location of most recent gcc libraries (part of our compiler toolchain) and then launching VS Code.
However, now that I am working remotely I cannot do that because VS Code is installed onto my laptop and I am using the SSH extension to access the code on my office workstation. Looking on the man page for clangd I cannot see a way to specify the path to the libstdc++ that I want to use. Is there a way, other than adding the libraries to the LD_LIBRARY_PATH upon startup/login, to bypass this issue?
I found a way, albeit a little bit hacky.
Export the new LD_LIBRARY_PATH on .zprofile (or equivalent for your shell. I am using zsh). Make sure that there are no VSCode servers running in the host. If there are, make sure to remove them.
In the settings.json file add the following line, to tell VSCode that you want the shell to be a login, interactive shell:
"terminal.integrated.shellArgs.linux": ["-l", "-i"]
Job done. Clangd now finds the correct libraries.
Another way to do this is to use env in your settings.json as follows:
"clangd.path": "env",
"clangd.arguments": [
"LD_LIBRARY_PATH=<your_custom_path>",
"/path/to/my/clangd"
],
I was trying to add a theme to my VS CODE and i needed to run the command: Enable Custom CSS and JS in the ctrl+shift+P. But when I type it, it says that there are no commands matching. Is there another way to do it?
I added the import in the settings.json like:
"vscode_custom_css.imports": [
"directoy/to/css"
]
but I can't apply.
From the extension's doc:
VERY IMPORTANT: Items in vscode_custom_css.imports must be URLs. Plain file paths are NOT URLs.
Windows File URL Example: file:///C:/Users/MyUserName/Documents/custom.css
The C:/ part is REQUIRED.
MacOS and Linux File URL Example: file:///Users/MyUserName/Documents/custom.css
Windows users
In Windows, make sure you run your VS Code in Administrator mode before enabling or disabling your custom style!
Mac and Linux users
The extension would NOT if Code cannot modify itself. The cases include:
Code files being read-only, like on a read-only file system or,
Code is not started with the permissions to modify itself.
You need to claim ownership on Code's installation directory, by running this command:
sudo chown -R $(whoami) <Path to Code>
The placeholder means the path to VSCode installation. It is typically:
/Applications/Visual Studio Code.app/Contents/MacOS/Electron, on MacOS;
/Applications/Visual Studio Code - Insiders.app/Contents/MacOS/Electron, on MacOS when using Insiders branch;
/usr/share/code, on most Linux;
/opt/visual-studio-code/ on Arch Linux.
Mac and Linux package managers may have customized installation path. Please double check your path is correct.
I want to install VS Code + some extensions (Java to be exact) on the PCs (CentOS) in our university lab. I installed the editor itself according to the official documentation, but I'm running into problems when I want to install extensions. I'm logging into the systems as root via ssh.
Running sudo code --install-extension vscjava.vscode-java-pack --user-data-dir /some/dir (source) runs successfully, and the extensions are available when VS Code runs as root. The problem is: When I start VS Code as another user, the extensions are not installed.
My questions are:
What is stored in the user-data-dir? Does it contain the location of the extensions-dir? If yes, is it wise to share it across all users of the system?
What is the recommended way to install extensions system wide for different users?
Thanks!
I also need to be able to install extensions systemwide, but there doesn't seem to be a way to do this. The best solution I've found is to write a batch file that installs the extensions and then starts VS Code. I have users run that scr
How is it possible to export all Visual Studio Code settings and plugins and import them to another machine?
With the current version of Visual Studio Code as of this writing (1.22.1), you can find your settings in:
~/.config/Code/User on Linux
%APPDATA%\Code\User (C:\Users\username\AppData\Roaming\Code\User) on Windows
~/Library/Application Support/Code/User/ on Mac OS X
The files are settings.json and keybindings.json. Simply copy them to the target machine.
Your extensions are in:
~/.vscode/extensions on Linux and Mac OS X
%USERPROFILE%\.vscode\extensions (C:\Users\username\.vscode\extensions) on Windows (i.e., essentially the same place as on Linux and Mac OS X)
Alternately, just go to the Extensions, show installed extensions, and install those on your target installation. For me, copying the extensions worked just fine, but it may be extension-specific, particularly if moving between platforms, depending on what the extension does.
There is an extension for Visual Studio Code, called Settings Sync.
It synchronises your settings by gist (Gist by GitHub). It works the same as the Atom.io extension called settings-sync.
UPDATE:
This feature is now build in VS Code, it is worth to switch to official feature.
(https://stackoverflow.com/a/64035356/2029818)
You can now sync all your settings across devices with VSCode's built-in Settings Sync. It's found under Code > Preferences > Turn on Settings Sync...
Similar to the answer given by Big Rich you can do the following:
$ code --list-extensions | xargs -L 1 echo code --install-extension
This will list out your extensions with the command to install them so you can just copy and paste the entire output into your other machine:
Example:
code --install-extension EditorConfig.EditorConfig
code --install-extension aaron-bond.better-comments
code --install-extension christian-kohler.npm-intellisense
code --install-extension christian-kohler.path-intellisense
code --install-extension CoenraadS.bracket-pair-colorizer
It is taken from the answer given here.
Note: Make sure you have added VS Code to your path beforehand. On mac you can do the following:
Launch Visual Studio Code
Open the Command Palette (⇧ + ⌘ + P) and type 'shell command' to find the
Shell Command: Install 'code' command in PATH command.
For posterity, this post mentions,
in the latest release of Visual Studio Code (May 2016) it is now possible to list
the installed extension in the command line
code --list-extensions
On Mac, execute something like:
"/Applications/Visual Studio Code.app//Contents/Resources/app/bin/code" --list-extensions
To install, use:
--install-extension <ext> //see 'code --help'
You can now synchronise all your settings across devices with Visual Studio Code's built-in Settings Sync. It's found under menu File → Preferences → Turn on Settings Sync...
Read more about it in the official documentation here.
Your user settings are in ~/Library/Application\ Support/Code/User.
If you're not concerned about synchronising and it's a one-time thing, you can just copy the files keybindings.json and settings.json to the corresponding folder on your new machine.
Your extensions are in the ~/.vscode folder. Most extensions aren't using any native bindings and they should be working properly when copied over.
You can manually reinstall those who do not.
I'm preferred my own way to synchronize all Visual Studio Code extensions between laptops, using .dotfiles and small script to perform updates automatically. This way helps me every time when I want to install all extensions I have without any single mouse activity in Visual Studio Code after installing (via Homebrew).
So I just write each new added extension to .txt file stored at my .dotfiles folder. After that I pull master branch on another laptop to get up-to-date file with all extensions.
Using the script, which Big Rich had written before, with one more change, I can totally synchronise all extensions almost automatically.
Script
cat dart-extensions.txt | xargs -L 1 code --install-extension
And also there is one more way to automate that process. Here you can add a script which looks up a Visual Studio Code extension in realtime and each time when you take a diff between the code --list-extensions command and your .txt file in .dotfiles, you can easily update your file and push it to your remote repository.
I've made a Python script for exporting Visual Studio Code settings into a single ZIP file:
https://gist.github.com/wonderbeyond/661c686b64cb0cabb77a43b49b16b26e
You can upload the ZIP file to external storage.
$ vsc-settings.py export
Exporting vsc settings:
created a temporary dump dir /tmp/tmpf88wo142
generating extensions list
copying /home/wonder/.config/Code/User/settings.json
copying /home/wonder/.config/Code/User/keybindings.json
copying /home/wonder/.config/Code/User/projects.json
copying /home/wonder/.config/Code/User/snippets
adding: snippets/ (stored 0%)
adding: snippets/go.json (deflated 56%)
adding: projects.json (deflated 67%)
adding: extensions.txt (deflated 40%)
adding: keybindings.json (deflated 81%)
adding: settings.json (deflated 59%)
VSC settings exported into /home/wonder/vsc-settings-2019-02-25-171337.zip
$ unzip -l /home/wonder/vsc-settings-2019-02-25-171337.zip
Archive: /home/wonder/vsc-settings-2019-02-25-171337.zip
Length Date Time Name
--------- ---------- ----- ----
0 2019-02-25 17:13 snippets/
942 2019-02-25 17:13 snippets/go.json
519 2019-02-25 17:13 projects.json
471 2019-02-25 17:13 extensions.txt
2429 2019-02-25 17:13 keybindings.json
2224 2019-02-25 17:13 settings.json
--------- -------
6585 6 files
PS: You may implement the vsc-settings.py import subcommand for me.
This is my syncing configuration repo for VSCodium (for Linux only). If you use VSCode, just replace the codium with code and the syncing will be fine.
https://github.com/vanvuvuong/codium_configuration
Enable Portable Mode
Portable Mode instructs Visual Studio Code to store all its configuration and plugins in a specific directory (called data/ in Windows and Linux and code-portable-data in macOS).
At any time you could copy the data directory and copy it on another installation.
VS Code provides 2 options to take care your settings. One is import/Export and other is Sync settings with github profile.
Follow below steps to Export VS code settings
Search for 'Profiles: Export' in the Command Palette (Ctrl+Shift+P).
Select 'what to export' and confirm by clicking on 'OK'
Name you export -
Select Local file which will download file
To import, choose 'Profiles: Import' from Command Palette
Often there are questions about the Java settings in Visual Studio Code. This is a big question and can involve advanced user knowledge to accomplish. But there is simple way to get the existing Java settings from Visual Studio Code and copy these setting for use on another PC. This post is using recent versions of Visual Studio Code and JDK in mid-December 2020.
There are several screen shots (below) that accompany this post which should provide enough information for the visual learners.
First things first, open Visual Studio Code and either open an existing Java folder-file or create a new Java file in Visual Studio Code. Then look at the lower right corner of Visual Studio Code (on the blue command bar). The Visual Studio Code should be displaying an icon showing the version of the Java Standard Edition (Java SE) being used. The version being on this PC today is JavaSE-15. (link 1)
Click on that icon (JAVASE-15) which then opens a new window named "java.configuration.runtimes". There should be two tabs below this name: User and Workspace. Below these tabs is a link named, "Edit in settings.json". Click on that link. (Link 2)
Two json files should then open: Default settings and settings.json. This post only focuses on the "settings.json" file.
The settings.json file shows various settings used for coding different programming languages (Python, R, and Java). Near the bottom of the settings.json file shows the settings this User uses in Visual Studio Code for programming Java.
These Java settings are the settings that can be "backed up" - meaning these settings get copied and pasted to another PC for creating a Java programming environment similar to the Java programming environment on this PC. (Link 3)
Link 1
Link 2
Link 3
For those looking for an export option for Visual Studio (not Code), use Tools menu, select "Export selected environment settings"