如何在visual studio中重新启动Task Runner?

时间:2017-11-22 22:09:09

标签: visual-studio gulp task-runner-explorer

我有一个gulp任务将我的.less文件转换为css。这样可以正常工作,直到less文件中出现语法错误。这会导致gulp崩溃并且Task Runner Explorer停止,我无法重新启动它。我必须卸载/重新加载项目才能更改语法错误。

如何重启Task Runner Explorer?

2 个答案:

答案 0 :(得分:0)

我正在使用Visual Studio 2017,并且在任务运行器资源管理器中可以右键单击我不想运行的任务,然后可以在其中按运行以启动该任务 图片:https://i.stack.imgur.com/gHYFy.png

答案 1 :(得分:0)

任务可以随时启动和重新启动。非终止任务,如“观察”任务,可以多次启动并并行运行,除非终止。启动任务的一种方法是在列表中双击它。上下文菜单中还有一个“运行”命令。

Task context menu with the "run" command

终止任务

今天我也遇到了同样的问题,但出于其他原因。显然,关闭关联的控制台窗口会终止任务。

Task Runner prompt to terminate a process

我记得在一些旧版本的 Visual Studio 中,我必须手动打开 Task Runner Explorer,否则任务将无法启动。

关于语法错误

为了避免重新启动任务的麻烦,添加某种类型的错误处理。对此可能有更多解决方案,但我使用了 this one。这是一个较短的版本:

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();
});