如何在构建时在VS Code中运行多个任务? [英] How to run multiple tasks in VS Code on build?

查看:162
本文介绍了如何在构建时在VS Code中运行多个任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用tasks.json版本2.0.0,我无法做到这一点,因此,在构建应用程序时,会同时运行多个任务.我正在使用gulp进行SCSS编译,并且可以单独运行Compile/minify cms.scss任务,因此任务本身不是问题,而仅是VS Code的任务运行程序.当我在VS Code中Run Build Task时,即使具有"group": "build",我的gulp任务也不会运行-只有dotnet一个.

Using tasks.json version 2.0.0, I have not been able to make it so that, when I build my application, multiple tasks are run at the same time. I'm using gulp for my SCSS compilation, and running my Compile/minify cms.scss task on its own works fine, so it's not a problem with the task itself, just VS Code's task runner. When I Run Build Task in VS Code, my gulp task is not being run, even though it has "group": "build" — only the dotnet one is.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/HpsCoreWeb.csproj"
            ],
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Compile/minify cms.scss",
            "type": "gulp",
            "task": "cms.scss:cms.min.css",
            "problemMatcher": "$node-sass",
            "group": "build"
        }
    ]
}

根据 VS代码任务文档:

:定义任务所属的组.在示例中,它属于test组.可以通过从命令面板中运行运行测试任务来执行属于测试组的任务.

group: Defines to which group the task belongs. In the example, it belongs to the test group. Tasks that belong to the test group can be executed by running Run Test Task from the Command Palette.

dotnet build任务正在成功执行,因此不应该同时运行另一个任务,该任务也是build组的一部分?我在做什么错了?

The dotnet build task is succeeding, so shouldn't the other task, which is also part of the build group, be run as well? What am I doing wrong?

推荐答案

问题是运行测试任务"和运行构建任务"未执行该特定组中的所有任务.通常,您会得到一个下拉选择,因此您可以选择要执行的任务.由于您已将其中一项任务指定为默认任务,因此将跳过选择,而是执行默认任务.

The problem is that "Run Test Task" and "Run Build Task" do not execute all tasks in that specific group. Usually you get a drop down selection so you can choose which task to execute. Since you have specified one of the tasks as default, the selection will be skipped and instead the default task is executed.

您可以通过添加依赖项来解决此问题.请看以下示例:

You can work around that by adding dependencies. Take the following example:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Echo 1",
            "command": "echo",
            "type": "shell",
            "args": [ "echo1" ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOn":["Echo 2"]
        },
        {
            "label": "Echo 2",
            "type": "shell",
            "command": "echo",
            "args": [ "echo2" ],
            "group": "build"
        }
    ]
}

由于Echo 1依赖于Echo 2,因此在执行Echo 1之前将先执行Echo 2.请注意,该定义是一个列表,因此可以指定多个任务.在这种情况下,任务将并行执行.

As Echo 1 depends on Echo 2, Echo 2 will be executed prior to executing Echo 1. Note that the definition is a list, so more than one task can be specified. In that case the tasks are executed in parallel.

在您的情况下,将"dependsOn":["Compile/minify cms.scss"]添加到您的主要构建任务中应执行这两个任务.

In your case adding "dependsOn":["Compile/minify cms.scss"] to your main build task should execute both tasks.

这篇关于如何在构建时在VS Code中运行多个任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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