How to run multiple tasks in VS Code on build?

好久不见. 提交于 2019-12-20 10:44:58

问题


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.

tasks.json

{
    "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"
        }
    ]
}

According to the VS Code Tasks documentation:

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.

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?


回答1:


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"
        }
    ]
}

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.

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




回答2:


Double check your settings are enabled for Gulp auto-detection. ("gulp.autoDetect": "on")




回答3:


Put A plugin in package.json var gulpLoadPlugins = require('gulp-load-plugins'), plugins = gulpLoadPlugins();

Read more about that plugin, see this How To Build And Develop Websites With Gulp may help



来源:https://stackoverflow.com/questions/52238171/how-to-run-multiple-tasks-in-vs-code-on-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!