如果任务运行器资源管理器任务失败,则取消构建 [英] Cancel Build if Task Runner Explorer Task Fails

查看:117
本文介绍了如果任务运行器资源管理器任务失败,则取消构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用visual studio task runner(2015)来运行绑定到build之前的Gulp任务。



我已经设置好了,当gulp任务失败时,它发送退出代码1,最后它说进程终止于代码1。但是构建仍在继续。



这将取消团队城市中的构建,因此似乎将Visual Studio中的Task Runner链接到了一个问题。



如果使用非0的代码退出,我该如何防止发生这种构建? 正确的,这似乎是一个任务亚军问题。如果BeforeBuild任务失败,任务运行者不会与MSBuild进行通信以停止构建。

为了解决这个问题,您可以通过项目的预构建来运行Gulp任务事件而不是通过Task Runner绑定。



设置预生成事件



对于类库,可以通过右键单击项目并选择 Properties - >来访问Build Events。编译 - >生成事件...



对于web项目,它们位于属性 - >生成事件



这是我用来在预生成事件中调用Gulp任务的命令,它将阻止MSBuild运行它退出失败:

$ p $ gdp -b $(ProjectDir)--gulpfile $(ProjectDir)gulpfile.js my-task $ b

这个命令调用Gulp传递工作目录的绝对路径和 gulpfile.js



注意:


  • 我发现所有类型的上下文和工作目录问题试图使用更直的命令如 gulp my-task

  • $(ProjectDir)是其中一个构建命令的宏
  • 假设Gulp全局安装: npm安装-g gulp 。请参阅 jonas.ninja 回答,以了解如何将此安装构建到命令中(或者不需要全局依赖的替代方案)。

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 end it says "Process terminated with code 1." however the build continues.

This will cancel the build in team city so seems an issue linked Task Runner inside visual studio.

How can I prevent the build from taking place if it exits with a code other than 0?

解决方案

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:

  • I found all kinds of context and working directory issues trying to use a more straight up command like gulp my-task.
  • $(ProjectDir) is one of the Macros for Build Commands.
  • It is assumed that Gulp is installed globally: 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).

这篇关于如果任务运行器资源管理器任务失败,则取消构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆