如何在Visual Studio Code中的launch.json中扩展$ PATH? [英] How to extend $PATH in launch.json in Visual Studio Code?

查看:427
本文介绍了如何在Visual Studio Code中的launch.json中扩展$ PATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些shell脚本,我想在Visual Studio Code调试期间按名称从代码中执行。我需要扩展$ PATH环境变量以使其发生。当前,我在launch.json中关注json。

I have some shell scripts, which I would like to execute by name from code during debugging in Visual Studio Code. I need to extend $PATH environment variable to make it happened. Currently, I have following json in 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}:$(pwd)/../bin/" 
},

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

But, it does not work. How can I extend $PATH environment variable in launch.json in Visual Studio Code?

推荐答案

Windows 平台上,我发现Visual Studio Code似乎区分大小写。如果变量名的拼写与计算机上的拼写不一致,则Visual Studio Code将忽略launch.json中的变量。

On Windows platform I found that Visual Studio Code seems to be case-sensitive. If the name of the variable is not spelled exactly as it is spelled on your machine, Visual Studio Code will ignore your variable from the launch.json.

例如,正确设置 path 环境变量(拼写为 Path 时),您需要在launch.json中添加以下内容。 / p>

For example, to properly set path environment variable when it is spelled Path, you would need to add the following to launch.json.

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

请参见 Launch.json属性变量替换
此处在变量替换下有关变量框的内容:

See Launch.json attributes and Variable Substitution in Visual Studio Code documentation for more information. Here what's mentioned there about the variable casing under Variable Substitution:


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

Note: Be sure to match the environment variable name's casing, for example ${env:Path} on Windows.

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

This is odd, because Windows is case-insensitive to the names of environment variables

这篇关于如何在Visual Studio Code中的launch.json中扩展$ PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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