Extension Manifest
Visual Studio Code extensions utilize a manifest file named package.json to define metadata and capabilities. This file contains essential information such as the extension's name, version, and icon, along with functionality contributions and publishing details. For a complete list of available fields, refer to the official documentation. Below, we highlight key development and publishing-related properties.
Activation Events
Activation events determine when an extension becomes active after installation. These are specified in the activationEvents array within package.json. For example, to activate immediate upon VS Code startup:
"activationEvents": [
"*"
]
To defer activation until after startup completes, use:
"activationEvents": [
"onStartupFinished"
]
To activate when opening files of a specific language, such as log files:
"activationEvents": [
"onLanguage:log"
]
Refer to the official activation events documentation for additional options.
Contribution Points
Contribution points define the capabilities an extension provides, ranging from language support features to simple commands or UI elements. For instance, to contribute a command:
{
"contributes": {
"commands": [
{
"command": "myExtension.greet",
"title": "Display Greeting",
"category": "Utility",
"icon": {
"light": "./icons/light/greet.svg",
"dark": "./icons/dark/greet.svg"
}
}
]
}
}
Implement the command in the extension's main file (e.g., extension.ts):
vscode.commands.registerCommand('myExtension.greet', () => {
console.log('Greeting initiated');
vscode.window.showInformationMessage('Hello!');
});
Users can then execute the command via the Command Palette (Ctrl+Shift+P).
To add a context menu item in the file explorer:
"menus": {
"explorer/context": [
{
"when": "resourceScheme == file",
"command": "myExtension.encodeBase64",
"group": "encoding"
}
]
}
This adds a right-click option for encoding files to Base64. Consult the contribution points reference for all available options.
Publishing Considerations
Use the vsce CLI tool to package and publish extensions. Key commands include:
vsce create-publisher [publisher-name]
vsce login [publisher-name]
vsce package
vsce publish
Review the official publishing guide thoroughly. Common issues and recommendations:
Engines Field
Specify the minimum compatible VS Code version. Avoid wildcards:
"engines": {
"vscode": "^1.20.0"
}
Ensure the @types/vscode devDependency version matches:
"devDependencies": {
"@types/vscode": "^1.20.0"
}
Token Authentication
If encountering 401 errors during login, verify that the Azure DevOps token is generated with "All accessible organizations" selected.
Publisher Setup
Ensure the publisher name is correctly created and linked to your account. Incorrect publisher configuration may prevent successful publishing.
Extension Logo
Consider creating a distinctive logo using open-source tools to enhance extension visibility in the marketplace.