Hello,
I am new to Visual Studio and am trying to set up an "Open folder" development and created the appropriate CppProperties.json and tasks.vs.json files with their configurations, environments and tasks.
I am using tasks.vs.json to define tasks to run a build script. This works, but I have one secondary question here:
I have multiple tasks that are almost exactly the same. The only thing that differs between the tasks is the "taskLabel" and one entry in "args". The relevant parts are:
"tasks": [
{
// some properties that are the same for all tasks ...
"taskLabel": "Build", // different between tasks
"args": [
"${env.SHELL_ARGS}",
"build" // different between tasks
]
},
{
// repeat of all the identical properties ...
"taskLabel": "Install", // different between tasks
"args": [
"${env.SHELL_ARGS}",
"install" // different between tasks
]
}
]
Looking at the reference, I don't see a way to define some "base" task and just take that, edit the few entries that differ, and use the result as a new task. I guess I am stuck having to repeat most of the fields in every task?
To my main question - I am working with two different toolchains, but all the tasks I defined work for both of them. The only different thing are the values of the environment variables, e.g. ${env.SHELL_ARGS} as I used above. Is there any way to refer to these ${env. ...} variables only from the current active configuration (i.e. the one selected in the VS toolbar)? In CppProperties.json, according to the reference I can define per-configuration environments, but this does not seem to work as expected.
E.g. I have something like
"configurations": [
{
"inheritEnvironments": [ "env_A" ],
"name": "A",
// other properties ..
"environments": [
{
"SHELL_ARGS": "args_A",
// other variables ...
"environment": "env_A"
}
]
},
{
"inheritEnvironments": [ "env_B" ],
"name": "B",
// ...
"environments": [
{
"SHELL_ARGS": "args_B",
// ...
"environment": "env_B"
}
]
}
]
However when I add both to my tasks, i.e. "inheritEnvironments": [ "env_A", "env_B" ], the tasks always uses "env_A", even when configuration B is selected ..
I want e.g. the task "Build" to use "SHELL_ARGS = args_A", when I select configuration A, and "SHELL_ARGS = args_B" when I select configuration B.
Is this possible? Or do I really have to copy paste not only the whole tasks, but also each task for each configuration, only adjusting the "inheritEnvironments" field?