如何在Visual Studio代码中的launch.json中扩展$ PATH?

问题描述 投票:5回答:2

我有一些shell脚本,我想在Visual Studio Code中调试时通过代码执行名称。我需要扩展$ PATH环境变量来实现它。目前,我在launch.json中关注了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}:$(pwd)/../bin/" 
},

但是,它不起作用。如何在Visual Studio Code中的launch.json中扩展$ PATH环境变量?

debugging visual-studio-code
2个回答
4
投票

在Windows平台上,我发现Visual Studio Code似乎区分大小写。如果变量的名称拼写不完全与您机器上拼写的拼写完全相同,则Visual Studio Code将忽略launch.json中的变量。

例如,要在path拼写时正确设置Path环境变量,您需要将以下内容添加到launch.json中。

"env": {
      "Path": "${env:Path};${workspaceFolder}\\node_modules\\.bin" 
},

有关详细信息,请参阅Visual Studio代码文档中的Launch.json attributesVariable Substitution。这里有关于Variable Substitution下的变量套管的内容:

注意:确保匹配环境变量名称的大小写,例如Windows上的$ {env:Path}。

这很奇怪,因为Windows对环境变量的名称不区分大小写


1
投票

我最终放弃了完成这项工作,但我所做的解决方法是在调试会话之前粘贴DOS命令以在终端中设置路径。就像是:

set PATH=C:\Python27\Lib\site-packages\pywin32_system32;%PATH%

有点难看,但至少它让我工作。我添加它作为对我的launch.json的评论,所以我随时可用。不完全确定会为您的Linux环境干净地传输,但值得一试(当然,对于您正在使用的shell进行适当的语法更改)。

© www.soinside.com 2019 - 2024. All rights reserved.