[英]How to fail the build from a Visual Studio Extension
I'm building a package manager, and I need to restore packages before each build. 我正在构建一个包管理器,我需要在每次构建之前恢复包。
I have hooked the DTE.OnBuildBegin to achieve this, which works fine, However if there is an error I need to fail the build. 我已经连接了DTE.OnBuildBegin来实现这一点,这很好,但是如果有错误我需要使构建失败。
I have discovered that I can add to the error list using the ErrorListProvider, which works great however the build still continues and succeeds. 我发现我可以使用ErrorListProvider添加到错误列表,它工作得很好但是构建仍然继续并成功。 Even worse is that if you click run rather than build, the restore fails but the code still runs. 更糟糕的是,如果单击“运行”而不是“构建”,则还原将失败,但代码仍会运行。 And because Visual Studio uses a different view while running you don't see the error list while it is running. 并且因为Visual Studio在运行时使用不同的视图,所以在运行时看不到错误列表。
How can I fail the build? 我怎么能失败?
The following code will cancel the build. 以下代码将取消构建。
DTE dte = (DTE)GetService(typeof(DTE));
dte.ExecuteCommand("Build.Cancel");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.