Is there a way to add custom variables that I can use in my launch.json
settings for debugging in VSCode? Currently, the only way I have found is to add them to my workspace settings and refer to the from the ${config}
predefined variable.
I'd like to define variables/properties in the launch.json
and use them. Here's an example of what that might look like if I wanted to add myCustomVar
to all my URLs:
{
"version": "0.2.0",
"myCustomVar": "my_value",
"configurations": [
{
"name": "Page 1",
"type": "chrome",
"request": "launch",
"url": "http://localhost/page1.html?customVar=${myCustomVar}",
"sourceMaps": true,
"webRoot": "${workspaceFolder}/dev"
},
{
"name": "Page 2",
"type": "chrome",
"request": "launch",
"url": "http://localhost/page2.html?customVar=${myCustomVar}",
"sourceMaps": true,
"webRoot": "${workspaceFolder}/dev"
}
}
Variables Reference. Visual Studio Code supports variable substitution in Debugging and Task configuration files. Variable substitution is supported inside key and value strings in launch.json and tasks.json files using ${variableName} syntax.
Otherwise, you should be able to add custom settings to your VS Code settings.json file (it will warn you about "Unknown Configuration Setting") and insert them using $ {config:myCustomVar}. Thanks for contributing an answer to Stack Overflow!
The variableID refers to entries in the inputs section of launch.json and tasks.json, where additional configuration attributes are specified. The following example shows the overall structure of a tasks.json that makes use of input variables: Currently VS Code supports three types of input variables:
Adding further environment variables is simply a case of extending the “env” dictionary with new key/value pairs. However, if you have a number of environment variables to add to the launch config, it might be easier to add a reference to a separate environment variable file, conventionally placed within a top level .envs folder and named .env.
Input variables might work?
Otherwise, you should be able to add custom settings to your VS Code settings.json file (it will warn you about "Unknown Configuration Setting") and insert them using ${config:myCustomVar}
.
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