Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode Custom Variables in Launch Settings?

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"
        }
}
like image 288
SpaceCowboy2071 Avatar asked Nov 08 '18 11:11

SpaceCowboy2071


People also ask

How do I use variables in Visual Studio Code?

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.

How do I add custom settings to a VS Code project?

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!

What is the variableid in a VS Code project?

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:

How do I add additional environment variables to a launch config?

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.


1 Answers

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}.

like image 133
mbomb007 Avatar answered Oct 08 '22 23:10

mbomb007