Cancel Build if Task Runner Explorer Task Fails

前端 未结 3 2124
深忆病人
深忆病人 2021-02-07 05:41

I am using visual studio task runner (2015) to run a Gulp task bound to before build.

I have set it up so that when the gulp tasks fails it sends exit code 1 and at the

3条回答
  •  爱一瞬间的悲伤
    2021-02-07 06:37

    You are correct in that this seems to be a Task Runner issue. The task runner does not communicate with MSBuild to stop a build if a BeforeBuild task fails.

    To get around this, you can run your Gulp task via the project's pre-build event instead of via the Task Runner bindings.

    Set the pre-build event

    For class libraries, you can access Build Events by right-clicking your project and selecting Properties -> Compile -> Build Events....

    For web projects, they are located at Properties -> Build Events.

    Here is the command I used to call the Gulp task in pre-build event, which will prevent the MSBuild from running if it exits with a failure:

    gulp -b $(ProjectDir) --gulpfile $(ProjectDir)gulpfile.js my-task

    This command calls Gulp passing absolute paths for working directory and gulpfile.js.

    Notes:

    • I found all kinds of context and working directory issues trying to use a more straight up command like gulp my-task.
    • $(ProjectDir) is one of the Macros for Build Commands.
    • It is assumed that Gulp is installed globally: npm install -g gulp. See jonas.ninja's answer for how to build this install into the command (or for an alternative that does not require the global dependency).

提交回复
热议问题