vscode-extension-publisher
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVS Code Extension Publisher
VS Code扩展发布指南
Guides users through setting up, packaging, and publishing VS Code extensions to the Visual Studio Marketplace, including PAT/publisher setup, pre-flight validation, and CI/CD automation.
引导用户完成VS Code扩展的配置、打包和发布到Visual Studio Marketplace的全流程,包括PAT/发布者账号配置、预检验证以及CI/CD自动化。
Repo Sync Before Edits (mandatory)
编辑前同步仓库(必填)
Before creating/updating/deleting files in an existing repository, sync the current branch with remote:
bash
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin
git pull --rebase origin "$branch"If the working tree is not clean, stash first, sync, then restore:
bash
git stash push -u -m "pre-sync"
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin && git pull --rebase origin "$branch"
git stash popIf is missing, pull is unavailable, or rebase/stash conflicts occur, stop and ask the user before continuing.
origin在现有仓库中创建/更新/删除文件前,需将当前分支与远程仓库同步:
bash
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin
git pull --rebase origin "$branch"如果工作区未清理,先暂存修改,同步后再恢复:
bash
git stash push -u -m "pre-sync"
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin && git pull --rebase origin "$branch"
git stash pop如果缺少远程仓库、无法拉取,或在变基/暂存时出现冲突,请停止操作并询问用户后再继续。
originInstructions
操作步骤
Step 1: Run Pre-flight Checks
步骤1:运行预检检查
Before anything else, validate the environment and project.
Run the bundled preflight script:
bash
bash scripts/preflight-check.shThis checks:
- Node.js and npm are installed
- is installed globally (installs it if missing)
@vscode/vsce - exists and has required fields
package.json - No SVG icons (marketplace restriction)
If the script is not available, manually verify:
- Node.js installed: (requires v18+)
node --version - npm installed:
npm --version - vsce installed: — if missing, run
vsce --versionnpm install -g @vscode/vsce - package.json exists in the extension root directory
在开始任何操作前,先验证环境和项目。
运行内置的预检脚本:
bash
bash scripts/preflight-check.sh该脚本会检查:
- 是否已安装Node.js和npm
- 是否已全局安装(如果缺失则自动安装)
@vscode/vsce - 是否存在且包含必填字段
package.json - 是否存在SVG图标(市场限制)
如果脚本不可用,手动验证以下内容:
- Node.js已安装:运行(要求v18+)
node --version - npm已安装:运行
npm --version - vsce已安装:运行—— 如果缺失,执行
vsce --versionnpm install -g @vscode/vsce - package.json存在于扩展根目录
Step 2: Validate package.json
步骤2:验证package.json
The following fields are required for publishing:
| Field | Description | Example |
|---|---|---|
| Extension identifier (lowercase, no spaces) | |
| Human-readable name | |
| Short description | |
| Semver version | |
| Your publisher ID | |
| Minimum VS Code version | |
| Marketplace categories | |
Recommended fields for better marketplace presence:
| Field | Description |
|---|---|
| Path to PNG icon (min 128x128px, no SVG) |
| GitHub repo URL |
| License identifier (e.g., |
| Search keywords (max 30) |
| Hex color for marketplace banner |
| |
If any required field is missing, help the user add it to .
package.json以下字段是发布必填项:
| 字段 | 描述 | 示例 |
|---|---|---|
| 扩展标识符(小写,无空格) | |
| 人类可读的名称 | |
| 简短描述 | |
| 语义化版本号 | |
| 你的发布者ID | |
| 最低VS Code版本要求 | |
| 市场分类 | |
推荐添加的字段,提升市场展示效果:
| 字段 | 描述 |
|---|---|
| PNG图标路径(最小128x128px,禁止使用SVG) |
| GitHub仓库URL |
| 许可证标识符(例如 |
| 搜索关键词(最多30个) |
| 市场横幅的十六进制颜色 |
| |
如果任何必填字段缺失,帮助用户添加到中。
package.jsonStep 3: Setup Azure DevOps PAT (if needed)
步骤3:配置Azure DevOps PAT(如需要)
If the user has never published before, guide them through PAT creation:
- Go to https://dev.azure.com — sign in (or create a free account)
- Click User Settings (gear icon) > Personal Access Tokens
- Click + New Token with these settings:
- Name: (or any descriptive name)
vsce-publish - Organization: Select All accessible organizations
- Expiration: Set a reasonable duration (max 1 year)
- Scopes: Click Custom defined > Marketplace > check Manage
- Name:
- Click Create and copy the token immediately (it won't be shown again)
Important: The PAT must have:
- Organization: "All accessible organizations" (not a specific org)
- Scope: Marketplace > Manage
如果用户从未发布过扩展,引导他们创建PAT:
- 访问https://dev.azure.com —— 登录(或创建免费账号)
- 点击用户设置(齿轮图标)> Personal Access Tokens
- 点击**+ New Token**,配置以下设置:
- 名称:(或其他描述性名称)
vsce-publish - 组织:选择All accessible organizations
- 有效期:设置合理时长(最长1年)
- 权限范围:点击Custom defined > Marketplace > 勾选Manage
- 名称:
- 点击Create并立即复制令牌(令牌只会显示一次)
重要提示:PAT必须满足:
- 组织:"All accessible organizations"(不是特定组织)
- 权限范围:Marketplace > Manage
Step 4: Create or Verify Publisher (if needed)
步骤4:创建或验证发布者账号(如需要)
If the user doesn't have a publisher identity:
- Go to https://marketplace.visualstudio.com/manage
- Sign in with the same Microsoft account used for the PAT
- Click Create publisher
- Fill in:
- ID: Unique identifier (cannot be changed later!)
- Name: Display name shown on marketplace
- Verify by running:
vsce login <publisher-id>- Enter the PAT when prompted
Make sure the field in matches the publisher ID exactly.
publisherpackage.json如果用户还没有发布者身份:
- 访问https://marketplace.visualstudio.com/manage
- 使用创建PAT时的同一Microsoft账号登录
- 点击Create publisher
- 填写信息:
- ID:唯一标识符(创建后无法修改!)
- 名称:在市场上显示的名称
- 通过运行以下命令验证:
vsce login <publisher-id>- 提示时输入PAT
确保中的字段与发布者ID完全一致。
package.jsonpublisherStep 5: Package the Extension
步骤5:打包扩展
Create a package for testing before publishing:
.vsixbash
vsce packageThis generates a file like .
my-extension-0.0.1.vsixTest locally before publishing:
bash
code --install-extension my-extension-0.0.1.vsixIf there are packaging errors:
- Missing README.md: Create a README.md in the project root
- SVG icon: Replace with a PNG file (min 128x128px)
- Missing license: Add a LICENSE file or set in package.json
"license"
在发布前创建包用于测试:
.vsixbash
vsce package这会生成类似的文件。
my-extension-0.0.1.vsix发布前本地测试:
bash
code --install-extension my-extension-0.0.1.vsix如果打包出错:
- 缺少README.md:在项目根目录创建README.md
- SVG图标:替换为PNG文件(最小128x128px)
- 缺少许可证:添加LICENSE文件或在package.json中设置字段
"license"
Step 6: Publish to Marketplace
步骤6:发布到市场
Once testing is satisfactory, publish:
bash
vsce publishVersion bump options:
bash
vsce publish patch # 1.0.0 → 1.0.1
vsce publish minor # 1.0.0 → 1.1.0
vsce publish major # 1.0.0 → 2.0.0
vsce publish 1.2.3 # Set exact versionIn git repos, automatically creates a version commit and tag.
vsce publishAfter publishing: The extension appears on the marketplace within ~5 minutes. Verify at:
https://marketplace.visualstudio.com/items?itemName=<publisher>.<extension-name>测试通过后,执行发布:
bash
vsce publish版本升级选项:
bash
vsce publish patch # 1.0.0 → 1.0.1
vsce publish minor # 1.0.0 → 1.1.0
vsce publish major # 1.0.0 → 2.0.0
vsce publish 1.2.3 # 设置精确版本在git仓库中,会自动创建版本提交和标签。
vsce publish发布后:扩展会在约5分钟内出现在市场上。通过以下链接验证:
https://marketplace.visualstudio.com/items?itemName=<publisher>.<extension-name>Step 7: Setup GitHub Actions CI/CD (Optional)
步骤7:配置GitHub Actions CI/CD(可选)
If the user wants automated publishing, generate a GitHub Actions workflow.
Copy the template from to the project:
assets/github-actions-publish.ymlbash
mkdir -p .github/workflows
cp assets/github-actions-publish.yml .github/workflows/publish.ymlThen guide the user to:
- Add the PAT as a GitHub secret named :
VSCE_PAT- Go to repo Settings > Secrets and variables > Actions
- Click New repository secret
- Name: , Value: the Azure DevOps PAT
VSCE_PAT
- Publishing triggers on git tags matching (e.g.,
v*)v1.0.0 - To release:
git tag v1.0.0 && git push origin v1.0.0
See for CI/CD customization options.
references/publishing-guide.md如果用户需要自动化发布,生成GitHub Actions工作流。
将模板从复制到项目中:
assets/github-actions-publish.ymlbash
mkdir -p .github/workflows
cp assets/github-actions-publish.yml .github/workflows/publish.yml然后引导用户完成以下操作:
- 将PAT添加为名为的GitHub密钥:
VSCE_PAT- 进入仓库Settings > Secrets and variables > Actions
- 点击New repository secret
- 名称:,值:Azure DevOps PAT
VSCE_PAT
- 当git标签匹配(例如
v*)时触发发布v1.0.0 - 发布方式:
git tag v1.0.0 && git push origin v1.0.0
查看获取CI/CD自定义选项。
references/publishing-guide.mdStep Completion Reports
步骤完成报告
After completing each major step, output a status report in this format:
◆ [Step Name] ([step N of M] — [context])
··································································
[Check 1]: √ pass
[Check 2]: √ pass (note if relevant)
[Check 3]: × fail — [reason]
[Check 4]: √ pass
[Criteria]: √ N/M met
____________________________
Result: PASS | FAIL | PARTIALAdapt the check names to match what the step actually validates. Use for pass, for fail, and to add brief context. The "Criteria" line summarizes how many acceptance criteria were met. The "Result" line gives the overall verdict.
√×—Pre-flight phase checks: , ,
Node.js availablevsce installedpackage.json validAuth Setup phase checks: ,
PAT configuredPublisher verifiedPackage phase checks: , ,
Extension packagedSize reasonableManifest correctPublish phase checks: , ,
Upload successMarketplace liveCI/CD configured完成每个主要步骤后,按以下格式输出状态报告:
◆ [步骤名称] ([第N步/共M步] — [上下文])
··································································
[检查项1]: √ 通过
[检查项2]: √ 通过(如有相关说明可补充)
[检查项3]: × 失败 — [原因]
[检查项4]: √ 通过
符合标准: √ N/M 已满足
____________________________
结果: 通过 | 失败 | 部分通过根据步骤实际验证的内容调整检查项名称。用表示通过,表示失败,用于添加简短上下文。“符合标准”行总结已满足的验收标准数量。“结果”行给出整体结论。
√×—预检阶段检查项:, ,
Node.js可用vsce已安装package.json有效认证配置阶段检查项:,
PAT已配置发布者已验证打包阶段检查项:, ,
扩展已打包大小合理清单正确发布阶段检查项:, ,
上传成功已上线市场CI/CD已配置Examples
示例
Example 1: First-Time Publishing
示例1:首次发布
User says: "I want to publish my VS Code extension to the marketplace"
Actions:
- Run preflight checks to verify environment
- Validate package.json — fill in any missing required fields
- Walk through PAT creation on Azure DevOps
- Create publisher identity on marketplace
- Login with
vsce login - Package with and test locally
vsce package - Publish with
vsce publish
Result: Extension live on VS Code Marketplace.
用户需求:"我想把我的VS Code扩展发布到市场"
操作步骤:
- 运行预检检查验证环境
- 验证package.json —— 补充任何缺失的必填字段
- 引导用户在Azure DevOps上创建PAT
- 在市场上创建发布者身份
- 运行登录
vsce login - 用打包并本地测试
vsce package - 用发布
vsce publish
结果:扩展已在VS Code Marketplace上线。
Example 2: Publish Update with Version Bump
示例2:升级版本并发布
User says: "publish a new minor version of my extension"
Actions:
- Run preflight checks
- Verify package.json is valid
- Run
vsce publish minor
Result: Version bumped and published (e.g., 1.0.0 → 1.1.0).
用户需求:"发布我的扩展的新版本(小版本升级)"
操作步骤:
- 运行预检检查
- 验证package.json有效
- 运行
vsce publish minor
结果:版本已升级并发布(例如1.0.0 → 1.1.0)。
Example 3: Setup CI/CD for Auto-Publishing
示例3:配置CI/CD自动发布
User says: "create a GitHub Actions workflow to auto-publish my extension"
Actions:
- Copy to
assets/github-actions-publish.yml.github/workflows/publish.yml - Guide user to add secret to GitHub repo
VSCE_PAT - Explain tagging workflow:
git tag v1.0.0 && git push origin v1.0.0
Result: Extensions auto-publish on version tags.
用户需求:"创建GitHub Actions工作流来自动发布我的扩展"
操作步骤:
- 将复制到
assets/github-actions-publish.yml.github/workflows/publish.yml - 引导用户将密钥添加到GitHub仓库
VSCE_PAT - 说明标签工作流:
git tag v1.0.0 && git push origin v1.0.0
结果:扩展会在创建版本标签时自动发布。
Error Handling
错误处理
401 Unauthorized / 403 Forbidden
401 Unauthorized / 403 Forbidden
Cause: PAT is invalid, expired, or has wrong scope.
Solution:
- Regenerate PAT at https://dev.azure.com with:
- Organization: "All accessible organizations"
- Scope: Marketplace > Manage
- Re-login:
vsce login <publisher-id>
原因:PAT无效、过期或权限范围错误。
解决方案:
- 在https://dev.azure.com重新生成PAT,确保:
- 组织:"All accessible organizations"
- 权限范围:Marketplace > Manage
- 重新登录:
vsce login <publisher-id>
"Extension already exists"
"Extension already exists"
Cause: Another publisher owns this extension name.
Solution: Change the field in to something unique. The can still be anything.
namepackage.jsondisplayName原因:该扩展名称已被其他发布者占用。
解决方案:修改中的字段为唯一值。仍可使用任意名称。
package.jsonnamedisplayNameSVG Icon Error
SVG图标错误
Cause: Marketplace prohibits SVG icons for security reasons.
Solution: Convert the icon to PNG format (minimum 128x128 pixels) and update the field in .
iconpackage.json原因:市场出于安全原因禁止使用SVG图标。
解决方案:将图标转换为PNG格式(最小128x128像素),并更新中的字段。
package.jsoniconMissing Fields in package.json
package.json缺少字段
Cause: Required fields are absent.
Solution: Run the preflight script to identify missing fields, then add them to .
package.json原因:必填字段缺失。
解决方案:运行预检脚本识别缺失字段,然后添加到中。
package.json"Exceeded 30 tags"
"Exceeded 30 tags"
Cause: Too many items in the array.
Solution: Reduce to 30 or fewer entries.
keywordskeywords原因:数组中的条目过多。
解决方案:将减少到30个或更少。
keywordskeywordsvsce package fails with prepublish error
vsce package执行时出现prepublish错误
Cause: The script in package.json failed.
Solution: Run the prepublish script manually to see the error:
vscode:prepublishbash
npm run vscode:prepublishFix the underlying build issue before retrying.
原因:package.json中的脚本执行失败。
解决方案:手动运行prepublish脚本查看错误:
vscode:prepublishbash
npm run vscode:prepublish修复底层构建问题后再重试。