2

Looking at the documentation for VSCode variable substitution, I was expecting the following tasks.json to perform variable substitution in the pick list when using the chooseDirectory code, but it just selects the literal string ${fileDirname} instead.

Can I get the substituted text to appear in the user selection menu?

{
   "version": "2.0.0",
   "command": "cmd",
   "args": ["/c"],
   "tasks": [
      {
         "label": "The task",
         "command": "my_batch_file.bat",
         "type": "shell",
         "args": [
            "${workspaceFolder}",
            "${input:chooseDirectory}"
         ],
         "problemMatcher": []
      }
   ],
   "inputs": [
      {
         "id": "chooseDirectory",
         "description": "Select the Directory",
         "type": "pickString",
         "options": ["option1", "${fileDirname}"],
         "default": "option1"
      }
   ]
}

When the task executes, this is what gets executed:

> Executing task: my_batch_file.bat C:\My\Workspace\Directory ${fileDirname} <

1 Answer 1

0

This issue suggests that variable substitution is currently not supported for inputs, but might be added sometime in the future:

consider to allow for variable substitution in the inputs section (#64358)

3
  • Many thanks for the reply, it's useful to see independent confirmation that I wasn't going mad ;-) Commented Jan 22, 2019 at 14:39
  • For reference, it was added in a release shortly afterwards (1.30.0) and it now works just as you'd expect. Commented May 9, 2019 at 13:01
  • Well spotted @Gama11. I'm retracting my comment above, ;-). I got round the problem in a different way and forgot that I didn't use this functionality in the end. I think it was the ${input:xxx} functionality that was added in 1.30.0 (to which I referred). Commented May 9, 2019 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.