I know there is ${workspaceRoot}
environment variable available. What other environment variables are there to use?
One that would be of particular interest would be the filename without the ${workspaceRoot}
part with all \
chars replaced with /
so we can use this as a url builder. Then you could use a URL like "http://localhost:9876/${relativeFile}
".
It would be really helpful if there is something like a ${relativeFile}
and a ${relativeFolder}
.
If you open the . vscode/launch. json file in your workspace or select Debug > Open Configurations then you should see a set of launch configurations for debugging your code. You can then add to it an env property with a dictionary of string:string.
${workspaceFolder} - the path of the folder opened in VS Code.
Using VS Code variables ${workspaceFolder} refers to the root of the workspace opened in VS Code. ${file} refers to the currently opened file. ${fileDirname} refers to the directory containing the currently opened file.
Once you have opened the folder, click on the Explorer icon on the top left corner of the VSCode (or press Ctrl+Shift+E) to open the explorer panel. In the explorer panel, click on the New File button as shown in the following screenshot: Then simply type in the new file name . env ...
Be aware the ${workspaceRoot}
variable has been deprecated in favor of the ${workspaceFolder}
variable. It was deprecated (and no longer documented) in order to align better with Multi-root workspace support.
You can find the list at this link: https://code.visualstudio.com/docs/editor/variables-reference
For posterity reasons I'm going to list the variables (I've been trying to find them as well today), copying right from the link (and prettifying it), in case it ever changes again:
Visual Studio Code supports variable substitution in Debugging and Task configuration files. Variable substitution is supported inside strings in launch.json and tasks.json files using ${variableName}
syntax.
The following predefined variables are supported:
Note: The ${workspaceRoot}
variable is deprecated in favor of the ${workspaceFolder}
variable.
You can also reference environment variables through ${env:Name}
syntax (for example, ${env:PATH}
)
{ "type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceFolder}/app.js", "cwd": "${workspaceFolder}", "args": [ "${env:USERNAME}" ] }
Note: Be sure to match the environment variable name's casing, for example ${env:Path}
on Windows.
You can reference VS Code settings and commands using the following syntax:
${config:Name}
- example: ${config:editor.fontSize}${command:CommandID}
- example: ${command:explorer.newFolder}By appending the root folder's name to a variable (separated by a colon), it is possible to reach into sibling root folders of a workspace. Without the root folder name, the variable is scoped to the same folder where it is used.
For example, in a multi root workspace with folders Server and Client, a ${workspaceFolder:Client}
refers to the path of the Client root.
You can find a list of available substitution variables here:
https://code.visualstudio.com/docs/editor/tasks#_variable-substitution
Edit: The full list can actually be found in the systemVariables.ts source file. The base class defines a resolve()
method that uses a regular expression to replace matches with string property values with the same name. Notice that SystemVariables
also includes all process.env
values, where the pattern is ${env.KEY}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With