如何在vscode中将输入变量从launch.json传递到tasks.json

Mr.*_*.EU 7 visual-studio-code vscode-tasks

我可以使用in中的输入变量launch.jsonlaunch.json

"configurations": [
  {
    ...
    "args": [${input:file_no}]
    "preLanuchTask": "runPreTasks"
    ...
  }
],
"inputs": [
  {
    "id": "file_no",
    "type": "promptString"
  }
]
Run Code Online (Sandbox Code Playgroud)

现在,我想访问相同的变量,而无需在 中再次输入输入tasks.json

{
  "version": "2.0.0",
  "tasks":[
    {
      "label": "runPreTasks",
      "type": "shell",
      "command": sh,
      "args": [
        "/path2script/scriptName.sh",
        "${input:file_no}"    // This does not work, without defining input again
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在 vscode 中传递输入launch.json变量tasks.json

Mr.*_*.EU 1

根据 @rioV8 的回答,我编辑了我的json文件,如下所示:

launch.json

"configurations": [
  {
    ...
    "args": [${input:file_no}]
    "preLanuchTask": "runPreTasks"
    ...
  }
],
"inputs": [
  {
    "id": "file_no",
    "type": "command",
    "command": "extension.commandvariable.promptStringRemember",
    "args": {
      "key": "lastnumber",
      "description": "Enter the number"
    }
  }
]
Run Code Online (Sandbox Code Playgroud)

tasks.json

{
  "version": "2.0.0",
  "tasks":[
    {
      "label": "runPreTasks",
      "type": "shell",
      "command": sh,
      "args": [
        "/path2script/scriptName.sh",
        "${input:file_no}"    
      ]
    }
  ]
  "inputs": [
    {
      "id": "file_no",
      "type": "command",
      "command": "extension.commandvariable.rememberPick",
      "args": { "key": "lastnumber" }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

  • 在应得的地方给予认可,并将 @rioV8 响应(而不是您自己的响应)标记为答案。如果不先阅读真正的答案,您的答案将无法立即生效。您可以随时在评论部分指出这篇文章,以表明您在阅读真实答案后做了什么。 (4认同)