首页 > 解决方案 > 如何在 Visual Studio Code 的 launch.json 中使用 IDE 变量

问题描述

我为我的 python 项目使用虚拟环境,我想配置命令以自动化调试。

到目前为止,我已经更改了python.pythonPathinlaunch.json并且我的意图是在使用自定义任务构建之前更新所有依赖项,其结构如下

{
   "version": "2.0.0",
   "tasks": [{
       "label": "echotest",
       "command": "python ...", // Could be any other shell command
       "args": ["test"],
       "type": "shell"
   }]
}

所以,我的问题是,是否有任何方法可以使用键内pythonPath定义的变量launch.jsoncommand

标签: visual-studio-codevscode-settingsvscode-tasks

解决方案


我的问题在这里得到回答,以防它帮助任何人。我的决赛tasks.json

{
   "version": "2.0.0",
   "tasks": [{
       "label": "update dependencies",
       "command": "${workspaceFolder}\\${config:python.pythonPath} -m pip -r ${workspaceFolder}\\requirements.txt",
       "args": [],
       "type": "shell"
   }]
}

注意文件夹名称中的空格,因为使用它们\"根本不起作用


推荐阅读