如何在vscode中构建,运行和删除可执行文件和虚拟文件

问题描述 投票:1回答:1

我想构建并运行c ++源代码。然后删除除源代码之外的所有内容。

{
  "tasks": [
    {
      "type": "shell",
      "label": "g++ build active file",
      "command": "/usr/bin/g++",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}",
        "&",
        "${fileDirname}/${fileBasenameNoExtension}",
        "&",
        "rm ",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "/usr/bin"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ],
  "version": "2.0.0"
}

我除了他们构建和运行,然后删除毫无价值的文件,但它不起作用。

c++ visual-studio-code
1个回答
1
投票

看看VScode tasks parameters,你会发现我们可以用dependsOn链接它们。请注意,所需的command可以包含工具所在位置的完整路径,当它不包含在您的OS路径变量中时,但options.cwd应该包含工具运行的路径,即${fileDirname}。此外,您应该研究presentation参数并根据您希望看到错误的方式进行调整。

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "g++ build active file",
      "command": "/usr/bin/g++",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}",
      ],
      "presentation": {
        "reveal": "silent",
        "panel": "shared"
      },
      "options": {
        "cwd": "${fileDirname}"
      },
    },
    {
      "label": "cpp-run",
      "type": "process",
      "command": "${fileDirname}/${fileBasenameNoExtension}",
      "dependsOn": [
        "g++ build active file"
      ],
      "presentation": {
        "reveal": "always",
        "panel": "shared"
      },
      "options": {
        "cwd": "${fileDirname}"
      },
    },
    {
      "label": "cpp-test",
      "type": "process",
      "command": "rm",
      "args": [
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "dependsOn": [
        "cpp-run"
      ],
      "presentation": {
        "reveal": "never",
        "panel": "shared"
      },
      "options": {
        "cwd": "${fileDirname}"
      },
    }
  ],
}
© www.soinside.com 2019 - 2024. All rights reserved.