23

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"
0

1 Answer 1

35

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.

Sign up to request clarification or add additional context in comments.

2 Comments

${fileBasenameNoExtension} the current opened file's basename without extension
Would it be possible to access the build directory through a variable or I have to hardcode it like ${workspaceFolder}/build/x64-Release/Foo.app/Contents/MacOS/Foo?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.