VS Code远程开发扩展跨Mac/Windows客户端失效问题排查与解决
VS Code远程开发跨客户端扩展被自动删除的问题及解决方法
问题描述
使用VS Code远程开发连接Ubuntu服务器,本地有Mac和Windows两台客户端。两台客户端均可正常使用VS Code基础功能,但从Mac客户端安装在服务器上的Python等扩展,切换到Windows客户端后完全无法使用,服务器端相关扩展被标记为已卸载并从磁盘删除。
服务器日志(Output->Remote Server)
2023-02-25 18:34:43.623 [info] Extension host agent started. 2023-02-25 18:34:43.780 [info] Marked extension as uninstalled ms-python.python-2022.16.1 2023-02-25 18:34:43.781 [info] Marked extension as uninstalled ms-python.vscode-pylance-2023.1.10 2023-02-25 18:34:43.781 [info] Marked extension as uninstalled ms-toolsai.jupyter-2022.8.1002431955 2023-02-25 18:34:43.781 [info] Marked extension as uninstalled ms-toolsai.jupyter-renderers-1.0.9 2023-02-25 18:34:43.787 [info] Deleted from disk ms-toolsai.vscode-jupyter-slideshow /home/xhpan/.vscode-server/extensions/ms-toolsai.vscode-jupyter-slideshow-0.1.5 2023-02-25 18:34:43.813 [info] Deleted from disk ms-toolsai.jupyter-renderers /home/xhpan/.vscode-server/extensions/ms-toolsai.jupyter-renderers-1.0.14 2023-02-25 18:34:43.842 [info] Deleted from disk ms-toolsai.vscode-jupyter-cell-tags /home/xhpan/.vscode-server/extensions/ms-toolsai.vscode-jupyter-cell-tags-0.1.6 2023-02-25 18:34:43.933 [info] Deleted from disk ms-toolsai.jupyter /home/xhpan/.vscode-server/extensions/ms-toolsai.jupyter-2023.1.2010391206 2023-02-25 18:34:43.988 [info] Deleted from disk ms-python.isort /home/xhpan/.vscode-server/extensions/ms-python.isort-2022.8.0 2023-02-25 18:34:44.006 [info] Deleted from disk ms-python.vscode-pylance /home/xhpan/.vscode-server/extensions/ms-python.vscode-pylance-2023.2.40 2023-02-25 18:34:44.010 [info] Deleted from disk ms-python.python /home/xhpan/.vscode-server/extensions/ms-python.python-2023.2.0 2023-02-25 18:34:44.712 [info] [127.0.0.1][4de3c107][ManagementConnection] New connection established. 2023-02-25 18:34:44.714 [info] [127.0.0.1][ca6b243b][ExtensionHostConnection] New connection established. 2023-02-25 18:34:44.725 [info] [127.0.0.1][ca6b243b][ExtensionHostConnection] <2579377> Launched Extension Host Process. 2023-02-25 18:39:43.624 [info] New EH opened, aborting shutdown
原因分析
这不是VS Code的Bug,而是扩展同步策略的限制。VS Code远程开发中,服务器端的扩展安装状态会和当前连接的客户端本地扩展设置同步。当不同客户端的扩展配置存在差异时,后连接的客户端会将自己的配置同步到服务器,导致之前安装的扩展被卸载。
具体来说,如果你在Mac客户端安装了服务器端扩展,但Windows客户端本地没有启用这些扩展的远程安装设置,当Windows客户端连接服务器时,会触发同步逻辑,把服务器上不符合Windows客户端配置的扩展删除。
解决方法
统一客户端的扩展远程安装配置
在两台客户端的VS Code中,确保需要在服务器端使用的扩展都设置为安装在远程:- 打开VS Code扩展面板,找到目标扩展(比如Python)
- 点击扩展卡片右下角的齿轮图标,选择「Install on SSH: [你的服务器名称]」
- 两台客户端都执行该操作,确保远程扩展的安装状态一致
禁用扩展自动同步
如果你不需要客户端与服务器的扩展配置自动同步,可以通过修改设置关闭该功能:- 打开VS Code设置(快捷键
Ctrl+,或Cmd+,) - 搜索
remote.extensions.autoSync,将该选项设置为false - 注意:关闭后需要手动管理服务器端的扩展安装,两台客户端连接时都不会自动同步扩展状态
- 打开VS Code设置(快捷键
使用工作区配置锁定扩展
如果只需要在特定项目中使用固定扩展,可以创建工作区配置文件.vscode/extensions.json,指定需要安装的扩展:{ "recommendations": [ "ms-python.python", "ms-python.vscode-pylance", "ms-toolsai.jupyter" ] }将该文件提交到项目仓库,两台客户端打开项目时,VS Code会提示安装推荐的远程扩展,避免配置差异导致的扩展删除。
内容的提问来源于stack exchange,提问作者Xuanhao Pan
相关产品推荐
相关产品推荐

