visit
Extension packs in VS Code are useful when we want to bundle and install a set of extensions together. It also provides us with a way to share and organize our favourite extensions.
npm install -g yo
npm install -g generator-code
yo code
+-- .vscode
| +-- launch.json
+-- .vscodeignore
+-- CHANGELOG.md
+-- package.json
+-- README.md
+-- vsc-extension-quickstart.md
vscode/launch.json
is a file used to configure the debugger in VS Code..vscodeignore
file excludes some files from being included in your extension's package.CHANGELOG.md
.README.md
is the project readme file, it'll also be used in the extension packs page in the VS Code marketplace.package.json
at the root of the project directory structure. Most of the time we'll find ourselves tweaking the manifest file. A great reference can be found here at .vsc-extension-quickstart.md
feature some quick-start tips.Cool, so now that we understand (hopefully 😅) what everything means! We can move forward to update the package.json
manifest to customize our extension pack. The field names are quite clear with their meaning.
"name": "adisakshya-extension-pack",
"displayName": "adisakshya-extension-pack",
"description": "Adisakshya's extension-pack for VS Code & Code Server",
"version": "1.0.0"
The extensionPack
field is a list of extension-ids
. The ID of the extension can be obtained from VS Code Marketplace.
"extensionPack": [
"cssho.vscode-svgviewer",
"docsmsft.docs-markdown",
"eamodio.gitlens",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
"formulahendry.code-runner",
"GitHub.github-vscode-theme",
"GrapeCity.gc-excelviewer",
"humao.rest-client",
"johnpapa.vscode-peacock",
"ms-azuretools.vscode-docker",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode-remote.vscode-remote-extensionpack",
"ms-vscode.cpptools",
"ms-vscode.vscode-typescript-next",
"ritwickdey.LiveServer",
"VisualStudioExptTeam.vscodeintellicode",
"vscode-icons-team.vscode-icons",
"vsls-contrib.codetour"
]
Its path has to be mentioned in the package.json
manifest like -
"icon": "path/to/icon-file.png"
npm install --global vsce
We'll choose to pack our extension into a VSIX
file, using which people who wish to use the same pack can install it.
vsce package
For users who receive the VSIX
file, they can install the extension pack on VS Code and code-server like so -
# VS Code
code --install-extension adisakshya-extension-pack-1.0.0.vsix
# Code Server
code-server --install-extension adisakshya-extension-pack-1.0.0.vsix
A handy NPM script can be included in package.json
-
"scripts": {
"pack": "vsce package"
}
This can be used as an npm run pack
or yarn run pack
in CI.
Okay... so it said - Unable to install extension 'adisakshya-extension-pack' as it is not compatible with VS Code '1.53.2'. I figured out that it had something to do with the version of VS Code for which the extension pack was created.
One thing that looked SUS was the engines.vscode
field inside package.json
, which was the only thing I left as default. I went through the VS Code Extension API Reference to find out what this field really is and what I found was -
When authoring an extension, you will need to describe what is the extension's compatibility to Visual Studio Code itself. —
The engines.vscode
field is an object that contains a key matching the versions of VS Code that the extension or extension pack is compatible with. If I'm generating the scaffolding code on my system then this field is set to the version of VS Code I'm using by default.
"engines": {
"vscode": "^1.56.0"
}
I was using the 1.56.0
version of VS Code and generated the VSIX file with this configuration. 1.53.0
was the version of VS Code associated with the code-server release that I was using.
Okay, the extension pack that I created was meant to be compatible with version 1.56.0
and above. While the code-server was using 1.53.0
— this was the reason for that incompatibility message!
I updated the engines.vscode
field to ^1.53.0
to make it work, but still, the installation failed on code-server as some extensions inside the pack were not compatible with this version of VS Code. So next possible solution was to upgrade the code-server.
I installed the 3.10.2
version of code-server which used VS Code 1.56.0
and tried installing my extension pack with engines.vscode
field set to 1.56.0
. Great, it worked!
Before packing our extension we must ensure that we’ve mentioned the
engines.vscode
field correctly according to our use.
To find out what version of VS Code engine is our code-server setup using, see the Welcome Screen - Publishing the extension pack
We'll be publishing the VSIX
file of our extension pack to a GitHub Release using Travis CI. Let’s define our expectations — The CI workflow should do the following -
Workspaces allow jobs within a build to share files. They are useful when you want to use build artefacts from a previous job. — Travis Workspaces Docs
VSIX files uploaded to a GitHub release can be downloaded using the curl command
. Then we can use the code [or code-server] --install-extension
command to install the extension pack. If you use an automation script to set up VS Code or code-server then this way you can write a single line in the script to install the extension pack as well.
So, let’s write the Travis CI configuration .travis.yml
-
# Language and Node Engine
language: node_js
node_js: 12
# Environment Variables
env:
global:
- PACK_NAME=adisakshya-extension-pack
- VERSION=$(node assets/version.js -p)
# Jobs
jobs:
include:
# STAGE 1
- stage: build
name: "Build"
install:
# Install VSCE
- npm install --global vsce
script:
# Pack extensions
- npm run pack
# Create a workspace
workspaces:
create:
name: ws1
# Upload artifact to the workspace
paths:
- ${PACK_NAME}-${VERSION}.vsix
# STAGE 2
- stage: GitHub Release
name: "Publish VSIX file on GitHub Release"
# Use an existing workspace
workspaces:
use: ws1
install: skip
script: skip
# Publish VSIX file to GitHub release
deploy:
provider: releases
api_key: ${GITHUB_SECURE_TOKEN} # The GitHub Access Token
name: ${VERSION} # Name of release is set as the version of extension pack
file: ${PACK_NAME}-${VERSION}.vsix # Attach VSIX file with the release
skip_cleanup: true
on:
tags: true
On success, the VSIX file will be published to a .
The following command will download and install the VSIX file from the latest GitHub release -
curl //github.com/adisakshya/extension-pack/releases/latest/download/adisakshya-extension-pack.vsix -O -L && \
code --install-extension adisakshya-extension-pack.vsix
//github.com/adisakshya/extension-pack/releases/download/<GIT_TAG>/adisakshya-extension-pack.vsix
Let’s use what we’ve created!
VS Code
Code Server
You can find a video demonstration of the installation .