我想构建并运行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"
}
我除了他们构建和运行,然后删除毫无价值的文件,但它不起作用。
看看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}"
},
}
],
}