I want to create tasks.json file in VSC. I know how to access predefined variables, environment variables, configuration variables... this is all nicely explained in variables reference page. But I have some configuration in another json files in my project - is there a way to access them? For the time being I just replicated the settings I need into settings.json - so I can access them like any other configuration variables - but this does not look right. Here is what I mean: I added the following to settings.json
"tq.appName" : "App Name",
"tq.appPublisher" : "Pub Name",
"tq.appVersion" : "1111111111",
"tq.targetDockerContainerName": "docker"
Then I can access them in my task:
"label": "Build APP and replace/publish in docker image",
"type": "shell",
"command": "${workspaceFolder}\\.vscode\\DevelopingDaily.ps1",
"args": [
{
"value": "${config:tq.appName}",
"quoting": "strong"
},
{
"value": "${config:tq.targetDockerContainerName}",
"quoting": "strong"
},
{
"value": "${workspaceFolder}\\${config:tq.appPublisher}_${config:tq.appName}_${config:tq.appVersion}.app",
"quoting": "strong"
}
]
But those values are stored in app.json file in project - not in settings.json. I would prefer to get the values directly from app.json - without the need to copy them over into settings... Is it possible?
You can use extension Command Variable command extension.commandvariable.file.content
Using config.json
file
{
"log": "foobar.log",
"server1": {
"port": 5011
},
"server2": {
"port": 5023
}
}
In your tasks.json you want to use the server1 port value.
{
"version": "2.0.0",
"tasks": [
{
"label": "echo Server1Port",
"type": "shell",
"command": "echo",
"args": [
"${input:configServer1Port}"
],
"problemMatcher": []
}
],
"inputs": [
{
"id": "configServer1Port",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/config.json",
"json": "content.server1.port",
"default": "4321"
}
}
]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.