Debugging 如何在Visual Studio代码中扩展launch.json中的$PATH?
我有一些shell脚本,我希望在VisualStudio代码中调试时按代码名执行这些脚本。我需要扩展$PATH环境变量以使其发生。目前,我在launch.json中有以下jsonDebugging 如何在Visual Studio代码中扩展launch.json中的$PATH?,debugging,visual-studio-code,Debugging,Visual Studio Code,我有一些shell脚本,我希望在VisualStudio代码中调试时按代码名执行这些脚本。我需要扩展$PATH环境变量以使其发生。目前,我在launch.json中有以下json { "name": "Debug-Linux", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "
{
"name": "Debug-Linux",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {
"PATH": "$PATH:$(pwd)/../bin/"
},
"showLog": true
}
"env": {
"Path": "${env:Path};${workspaceFolder}\\node_modules\\.bin"
},
我也试过了
"env": {
"PATH": "${env.PATH}:$(pwd)/../bin/"
},
但是,它不起作用。如何在Visual Studio代码中扩展launch.json中的$PATH环境变量 我最终放弃了这项工作,但我所做的变通方法是在调试会话之前粘贴DOS命令以设置终端中的路径。比如:
set PATH=C:\Python27\Lib\site-packages\pywin32_system32;%PATH%
有点难看,但至少它能让我工作。我将其作为注释添加到我的launch.json中,以便随时可以使用。我不完全确定这是否会在Linux环境中干净地传输,但值得一试(当然要对您使用的shell进行适当的语法更改)。在Windows平台上,我发现Visual Studio代码似乎区分大小写。如果变量名称的拼写与您计算机上的拼写不完全相同,Visual Studio代码将忽略launch.json中的变量
{
"name": "Debug-Linux",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {
"PATH": "$PATH:$(pwd)/../bin/"
},
"showLog": true
}
"env": {
"Path": "${env:Path};${workspaceFolder}\\node_modules\\.bin"
},
例如,要在拼写为path
时正确设置path
环境变量,需要将以下内容添加到launch.json中
{
"name": "Debug-Linux",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {
"PATH": "$PATH:$(pwd)/../bin/"
},
"showLog": true
}
"env": {
"Path": "${env:Path};${workspaceFolder}\\node_modules\\.bin"
},
有关详细信息,请参见Visual Studio代码文档中的和。
以下是关于可变外壳的内容:
注意:确保与环境变量名的大小写匹配,例如Windows上的${env:Path}
这很奇怪,因为Windows对环境变量的名称不区分大小写根据,您应该使用
${env:PATH}
而不是${env.PATH}
这可能有助于我的工作,但vscode抱怨不允许使用env属性,所以我将其更改为:“environment”:[{“name”:“PATH”,“值”:“${env:Path};${workspaceFolder}\\node\u modules\\.bin”}],