如何在 vscode 工作区文件夹之间共享任务? [英] How to share tasks between vscode workspace folders?

查看:29
本文介绍了如何在 vscode 工作区文件夹之间共享任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 VSCode 项目是多根工作区.也就是说,我有多个工作区,每个工作区都在不同的目录中,每个都有一个 .vscode 文件夹.

My VSCode project is multi-root workspace. That is I have multiple workspaces each in separate directories, each has a .vscode folder.

我正在尝试通过构建任务构建一个在每个模块之间具有依赖关系的工作区.

I'm trying to build a workspace with dependencies between each module via build tasks.

我尝试为任务设置dependsOn参数,但它产生以下错误:

I've tried to set dependsOn parameter for a task, but it yields a following error:

无法解析工作区文件夹BAR"中的依赖任务build FOO"(此处 BAR 构建任务取决于 FOO)

是否有更好/正确/任何方式来实现我的目标?

Is there a better/correct/any way to achieve my goal?

推荐答案

您可以在 .code-workspace 文件中有一个 tasks 部分.在那里你可以创建一个像Build all"这样的任务并定义 dependsOn 任务.但是,您也无法从工作区文件夹中引用构建任务(对我来说,这听起来是一个合理的功能,我相信他们应该在某个时候实现它).我的解决方法是将相关的构建任务从子任务文件复制到 .code-workspace 文件中,并在我的全部构建"任务中引用它们.

You can have a tasks section in your .code-workspace file. There you can create a task like "Build all" and define dependsOn tasks. However, there you also cannot reference build tasks from the workspace folders (to me this sounds like a reasonable feature and I believe they should implement it at some time). My workaround is to copy the relevant build task from the sub-tasks files into the .code-workspace file and reference them in my "Build all" task.

示例.code-workspace:

{
    "folders": [
        {
            "path": "proj-A"
        },
        {
            "path": "proj-B"
        }
    ],
    "tasks": {
        "version": "2.0.0",
        "tasks": [
            {
                "type": "shell",
                "label": "Build A",
                "command": "make",
                "args": ["-j4"],
                "options": {
                    "cwd": "${workspaceFolder}/../proj-A",
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": "build",
            },
            {
                "type": "shell",
                "label": "Build B",
                "command": "make",
                "args": ["-j4"],
                "options": {
                    "cwd": "${workspaceFolder}/../proj-B",
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": "build",
            },
            {
                "type": "shell",
                "label": "Build all",
                "command": "echo",
                "args": ["Building everything"],
                "options": {},
                "problemMatcher": [
                    "$gcc"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "dependsOrder":"sequence",
                "dependsOn": ["Build A", "Build B"]
            },
        ]
    }
}

注意各个构建任务中的 cwd 选项.${workspaceFolder} 似乎被设置为 "folders" 部分的第一个路径.您还可以将 cwd 设置为绝对路径.

Note the cwd option in the individual build tasks. ${workspaceFolder} seems to be set to the first path in the "folders" section. You could also set cwd to absolute paths.

这有点hacky,而且必须复制构建任务这一事实并不美观,但它目前有效,一旦可以引用子任务文件的任务,就可以轻松适应.

This is a bit hacky and the fact that one has to copy the build tasks is not beautiful, but it works for now and it can be easily adapted once it is possible to reference tasks of sub-tasks files.

这篇关于如何在 vscode 工作区文件夹之间共享任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆