我有一个用 C 语言编写的项目,它有两个 make 文件,一个在主目录中,一个在子目录中。我想使用 VS Code 任务来自动化制作过程,这样我就不必在每次运行时都使用终端来制作项目。相反,我只想使用 ctrl+shift+b
,然后使用 mpiexec
从终端运行我的代码。
我在项目主文件夹内的 .vscode 目录中创建了 tasks.json 文件。 tasks.json 当前包含以下代码,我基于 this tutorial.
{
"version": "2.0.0",
"command": "bash",
"tasks": [
{
"label": "Make Project",
"type": "shell",
"command": "cd ${workspaceFolder}",
"args": ["make"],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"problemMatcher": "$msCompile"
}
]
}
我希望这与在当前工作目录的位置在终端中键入 make
的效果相同。相反,这是终端的输出
Executing task: 'cd /home/git/project' make <
/bin/bash: cd /home/git/project: no such file or directory
The terminal process terminated with exit code: 127
Terminal will be reused by tasks, press any key to close it.
请注意,make 文件位于/home/git/project。我还希望在/home/git/project/subfolder 中构建一个 make 文件。
为什么初始命令 cd/home/git/project
和 make
不工作?我是否需要与运行者一起将其分成几个不同的任务?我是使用 VS Code 的新手,因此非常感谢您的帮助。谢谢。
最佳答案
我实现的解决方案如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "msvc build",
"type": "shell",
"command": "",
"args": [
"make",
"--directory=${workspaceFolder};",
"make",
"--directory=${workspaceFolder}/subfolder"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal":"always"
},
"problemMatcher": "$msCompile"
}
]
}
基于 Reinier Torenbeek's suggestion以及this post on Microsoft's page.这里要注意的要点是我没有向 shell 传递任何命令,而是只传递参数。
我现在可以通过在编辑器中按 ctrl+shift+b
来构建项目中的所有 makefile,因为 group
设置为 build
.
关于c - 使用 Visual Studio Code 任务自动化多个文件夹中的 C 生成文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57808398/