0

I have a gulp task to convert my .less file to css. This works fine until there is a syntax error in the less file. This causes gulp to crash and the Task Runner Explorer stops and I can't restart it. I have to unload/reload the project to change a syntax error.

Any ideas how to restart the Task Runner Explorer?

Ray
  • 2,766
  • 13
  • 20
  • Might need some more details here, but also be sure to check out [Gulp task failing when run from VS 2015 Task Runner explorer, but not from command prompt](https://stackoverflow.com/a/35905376/1464112). The solution may solve it for you with an updated version of Node.js. – scniro Nov 22 '17 at 22:22
  • That didn't help but thanks. I guess my question boils down to this: How do I restart the Task Runner within visual studio? *edit* Changed title – Ray Nov 22 '17 at 22:52

2 Answers2

1

I'm using visual studio 2017 and in the task runner explorer you can right click the task I wan't to run and there you can press run to start that task Pic: https://i.stack.imgur.com/gHYFy.png

0

Tasks can be started and restarted any time. Non-terminating tasks, like "watch" tasks, can be started multiple times and will run in parallel, unless terminated. One way to start a task is to double click on it in the list. There is also a "run" command in the context menu.

Task context menu with the "run" command

Terminating a task

I had this same question today, but for other reasons. Apparently closing the associated console window terminates the task.

Task Runner prompt to terminate a process

I remember in some older version of Visual Studio I had to open Task Runner Explorer manually, otherwise the tasks would not start.

Regarding syntax errors

To save yourself from the trouble of restarting a task, add some type of error handling. There are probably more solutions to this, but I used this one. Here's a shorter version:

const gulp = require('gulp');
const plumber = require('gulp-plumber');
const lessCompiler = require('gulp-less');

const lessFiles = 'Styles/**/*.less';
const compileLessTaskName = 'compile-Less';
gulp.task(compileLessTaskName, function () {
  return gulp.src(lessFiles)
    // Calling plumber at the start of the pipeline. In case of error, this stops
    // the task without killing the whole process.
    .pipe(plumber(function (error) {
      console.log(error.message);
      this.emit('end');
    }))
    .pipe(lessCompiler())
    .pipe(gulp.dest('wwwroot/css'));
});

gulp.task('watch', function (asyncCallback) {
    gulp.watch(lessFiles, [compileLessTaskName]);
    asyncCallback();
});
Andrius R.
  • 79
  • 6