Kirk Liemohn
Kirk Liemohn

Reputation: 7923

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"

Upvotes: 23

Views: 25155

Answers (1)

Steffen
Steffen

Reputation: 3516

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.

Upvotes: 35

Related Questions