当用户卸载您的 VSCode 扩展时如何执行代码? [英] How to execute code when user uninstalls your VSCode Extension?

查看:36
本文介绍了当用户卸载您的 VSCode 扩展时如何执行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

这是刚刚在 v1.21 中添加的:扩展卸载钩子

<块引用>

如果您的扩展在从 VS Code 卸载时需要进行一些清理,您现在可以通过将节点脚本注册到卸载挂钩 vscode:uninstall 中的扩展 package.json 的脚本部分下来实现.

<代码>{脚本":{"vscode:uninstall": "节点 ./out/src/lifecycle"}}

<块引用>

当扩展从 VS Code 中完全卸载时,即在卸载扩展后重新启动(关闭和启动)VS Code 时,将执行此脚本.

注意:仅支持 Node.js 脚本.

I read the entire visual studio code extensibility documentation and didn't find something like that. I wanna do a clean up, not when extension is deactivated but when it is uninstalled. I also try using the "uninstall" and "postUninstall" scripts fields from package.json but it didn't execute the scripts. Is this even possible?

解决方案

This was just added in 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.

这篇关于当用户卸载您的 VSCode 扩展时如何执行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆