Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common variables for launch.json in Visual Studio Code

I have seen how launch.json for Visual Studio Code has access to ${workspaceFolder}. Does it also have access to other common variables? I would like to have access to the current user's AppData folder so I can do:

"program": "${appData}\\Roaming\\npm\\node_modules\\gulp\\bin\\gulp.js"

instead of hard-coding it as:

"program": "C:\\Users\\jdoe\\AppData\\Roaming\\npm\\node_modules\\gulp\\bin\\gulp.js"
like image 455
Kirk Liemohn Avatar asked Oct 03 '16 17:10

Kirk Liemohn


People also ask

How do I launch VS code json?

vscode folder in your workspace (project root folder) or in your user settings or workspace settings. To create a launch. json file, click the create a launch. json file link in the Run start view.

Where is the launch json file in vscode?

The launch. json file is located in a . vscode folder in your workspace (project root folder).

How do I create a launch file in VS code?

js Apps with Visual Studio Code. Click on Run and Debug in the Activity Bar (⇧⌘D (Windows, Linux Ctrl+Shift+D)) and then select the create a launch. json file link to create a default launch.


1 Answers

Variable substitution in launch.json supports environment variables. For your use-case you can use ${env:AppData}.

VS Code supports variable substitution inside strings in launch.json the same way as for tasks.json.

https://code.visualstudio.com/docs/editor/tasks#_variable-substitution

  • ${workspaceFolder} the path of the folder opened in VS Code
  • ${file} the current opened file
  • ${relativeFile} the current opened file relative to workspaceRoot
  • ${fileBasename} the current opened file's basename
  • ${fileDirname} the current opened file's dirname
  • ${fileExtname} the current opened file's extension
  • ${cwd} the task runner's current working directory on startup

You can also reference environment variables through ${env:Name} (e.g. ${env:PATH}). Be sure to match the environment variable name's casing, for example env:Path on Windows.

like image 81
Steffen Avatar answered Sep 24 '22 02:09

Steffen