Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend $PATH in launch.json in Visual Studio Code?

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
}

Also, I've tried

"env": {
      "PATH": "${env.PATH}:$(pwd)/../bin/" 
},

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

like image 664
Aliaksei Maniuk Avatar asked Dec 05 '17 21:12

Aliaksei Maniuk


People also ask

How do I edit vs json in launch code?

In Visual Studio Code, use shortcut Ctrl + Shift + P to open the Command Palette and type Open launch. json . And it will open the launch.

How do you create launch json in Visual Studio Code?

To create a launch. json file, click the create a launch. json file link in the Run start view. If you go back to the File Explorer view (Ctrl+Shift+E), you'll see that VS Code has created a .

How do I change the path code in Visual Studio?

Windows and Linux installations should add the VS Code binaries location to your system path. If this isn't the case, you can manually add the location to the Path environment variable ( $PATH on Linux). For example, on Windows, VS Code is installed under AppData\Local\Programs\Microsoft VS Code\bin .

How do I add an extension to a Visual Studio Code?

You can browse and install extensions from within VS Code. Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (Ctrl+Shift+X). This will show you a list of the most popular VS Code extensions on the VS Code Marketplace.


1 Answers

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.

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" 
},

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:

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

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

like image 146
dmytroUa Avatar answered Sep 21 '22 02:09

dmytroUa