Cancel Build if Task Runner Explorer Task Fails

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

    I have build fail for jshint with gulp working (well enough for me, maybe sufficient for others.) I imagine it may be extended to include all the tasks in Task Runner.

    Here is what I used/did...

    As per this page, I added/edited this in my project.json, which hooks into the prebuild event...

      "scripts": {
        "prebuild": [ "gulp default" ]
      }
    

    As per this page, I included the following for my jshint task...

    // =============================
    // jsHint - error detection
    // =============================
    gulp.task("jshint", function () {
        var jshGlobals = [
            '$',
            'jQuery',
            'window',
            'document',
            'Element',
            'Node',
            'console'
        ];
    
        gulp.src([paths.jsFiles, norefs])
            .pipe(jshint({
                predef: jshGlobals,
                undef: true,
                eqnull: true
            }))
            .pipe(jshint.reporter('jshint-stylish'))
            .pipe(jshint.reporter('fail'))
    });
    

    The latter two lines being the most significant. You will need to npm install jshint-stylish if you don't already have it.

    Alternatively, for jshint-stylish, you can let VS handle it for you. Add the line for jshint-stylish as indicated below to your package.json...

    {
      "name": "ASP.NET",
      "version": "0.0.0",
      "devDependencies": {
        "es6-promise": "~3.1.2",
        "gulp": "^3.8.11",
        "del": "^2.2.0",
        "jshint": "~2.9.1",
        "jshint-stylish": "~2.1.0",
        "gulp-jshint": "~2.0.0",
        "gulp-flatten": "~0.2.0",
        "gulp-rename": "~1.2.2",
        "gulp-cssmin": "0.1.7",
        "gulp-uglify": "1.2.0",
        "gulp-postcss": "~6.1.0",
        "autoprefixer": "~6.3.3"
      }
    }
    

    Which gives me this when there is an error (in addition to the failed build) which is sufficient for me to dig further if/as necessary...

    As opposed to the more detailed error info I get when running the same task via command line or Task Runner...

    I imagine this solution can be improved but figured I would share as I hadn't seen a whole lot about it elsewhere.

    Cheers.

提交回复
热议问题