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
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:
gulp my-task
. $(ProjectDir)
is one of the Macros for Build Commands.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).