Cancel Build if Task Runner Explorer Task Fails

前端 未结 3 2153
深忆病人
深忆病人 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:16

    I implemented davidmdem's solution above and it was great... on my system. I had gulp installed globally, but one of my coworkers did not, so the pre-build event would fail. Running gulp from Task Runner Explorer uses the project-level gulp installation, but running gulp from the pre-build script uses the global gulp installation.

    To prevent the situation where a new developer doesn't have gulp installed, I expanded davidmdem's pre-build script to the following: (gulp --version || npm install -g gulp@3.9.0) & gulp -b $(ProjectDir) --gulpfile $(ProjectDir)gulpfile.js my-task

    This command installs gulp (version 3.9.0 to match the project-level gulp installation) only if it is not already installed. Now gulp is not something that you have to think about before you can build the project!


    (Update:)

    An alternative (in my opinion: better) solution to this problem is to use npm as an intermediary. Continuing and modifying from the example above, I have a gulp task my-task that is being called from the command line. This removed the global gulp dependency and still properly stops msbuild if gulp fails.

    Pre-build event:

    npm run build
    

    package.json:

    "scripts": {
      "build": "gulp min"
    }
    

提交回复
热议问题