下面给你一份从 0 到发布成功的 VS Code 插件完整流程,按实际工程步骤来讲,不走弯路,适合你现在这种已经在写 extension 代码的场景。 一、发布 VS Code 插件的整体流程 一句话流程: 注册发布者 → 准备插件配置 → 本地验证 → 登录 vsce → 发布 → 版本维护 二、前置条件(必须具备) 1️⃣ Microsoft 账号 用于登录 Visual Studio Marketplace 任意 Microsoft 账号即可(Outlook / Hotmail) 2️⃣ Node.js 环境 node -v # 建议 >= 16 npm -v 3️⃣ 安装发布工具 vsce npm install -g @vscode/vsce 验证: vsce --version 三、注册 Publisher(只做一次) 1️⃣ 打开 Marketplace 管理页面 👉 https://marketplace.visualstudio.com/manage 使用 Microsoft 账号登录 2️⃣ 创建 Publisher Publisher Name:发布者标识(不可改) Display Name:展示名(可读) ⚠️ publisher 一旦创建,插件里必须一致 例如: Publisher Name: hudachang Display Name: Hu Dachang 四、配置你的插件(关键) package.json 必须包含这些字段 { "name": "reverse-deps", "displayName": "Reverse Dependencies Viewer", "description": "View reverse import dependencies in workspace", "version": "0.0.1", "publisher": "hudachang", "engines": { "vscode": "^1.80.0" }, "categories": ["Other"], "activationEvents": [ "onView:reverseDepsView" ], "main": "./dist/extension.js", "contributes": { "views": { "explorer": [ { "id": "reverseDepsView", "name": "Reverse Dependencies" } ] } } } 常见易错点 项目 要求 publisher 必须和 Marketplace 中的一致 version 每次发布必须递增 main 指向编译后的 js engines.vscode 不要太老 五、打包前准备(非常重要) 1️⃣ 编译 TS(如果你用 TypeScript) npm run build 确保生成: dist/extension.js 2️⃣ 忽略不必要文件(可选但推荐) 创建 .vscodeignore: node_modules src .git .vscode *.ts tsconfig.json 3️⃣ 本地验证插件是否可用 vsce package 会生成: reverse-deps-0.0.1.vsix 本地安装测试: code --install-extension reverse-deps-0.0.1.vsix 六、登录 vsce(一次即可) 1️⃣ 创建 Personal Access Token(PAT) User Settings → Personal Access Tokens Scope 勾选: ✅ Marketplace (Manage) 2️⃣ 登录 vsce login hudachang 输入刚才生成的 token 七、发布插件 🚀 vsce publish 或指定版本: vsce publish patch # 0.0.1 -> 0.0.2 vsce publish minor # 0.1.0 vsce publish major # 1.0.0 发布成功后: 👉 https://marketplace.visualstudio.com/items?itemName=hudachang.reverse-deps 八、后续版本更新流程(你以后只做这三步) 1. 改代码npm run build 2. 更新版本vsce publish patch 九、常见问题与坑(你很可能会遇到) ❌ 1. Publisher not found 原因: package.json 的 publisher 和 Marketplace 不一致 ❌ 2. main 文件不存在 原因: TS 没编译 dist 目录没生成 ❌ 3. 插件能打包但激活失败 检查: activationEvents view id 是否一致 contributes.views 的 id |