I am trying to define my own environment variables in the tasks.json in VSCode. Following every link I have found so far, I tried the following:
{
"version": "2.0.0",
"type": "shell",
"options": {
"env": {
"APP_NAME": "myApp"
}
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": false
},
"tasks": [
{
"label": "Build Release",
"command": "python ./scripts/build_app.py $APP_NAME",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
I need this because we are running our build process via a python script and therefore I need to give it the name of the application I want to build. As I am having also python scripts for testing, executing, debugging and so on, I would prefer to change the app name only once in the tasks.json and not in every task itself.
According to the guidelines this should be possible in the way I did it, but in the powershell console the $APP_NAME variable is not substituted. Also neither in the cmd nor bash shell it seems to work.
I would be very grateful for any help someone could give me.
解决方案
Use$env:APP_NAME in your case. See referencing environment variables.
Environment variables
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.