当用户卸载您的 VSCode 扩展程序时如何执行代码?

How to execute code when user uninstalls your VSCode Extension?

我阅读了整个 visual studio 代码扩展性文档,但没有找到类似的内容。我想做一个清理,不是在扩展被停用时,而是在它被卸载时。我也尝试使用 package.json 中的 "uninstall" 和 "postUninstall" 脚本字段,但它没有执行脚本。这可能吗?

这只是在 v1.21 中添加的:Extension uninstall hook

If your extension has some clean ups to be done when it is uninstalled from VS Code, you can now do that by registering a node script to the uninstall hook vscode:uninstall under scripts section in extension's package.json.

{
  "scripts": {
    "vscode:uninstall": "node ./out/src/lifecycle"
  }
}

This script gets executed when the extension is completely uninstalled from VS Code which is when VS Code is restarted (shutdown and start) after the extension is uninstalled.

Note: Only Node.js scripts are supported.