trampster
trampster

Reputation: 8898

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.

I have discovered that I can add to the error list using the ErrorListProvider, which works great however the build still continues and succeeds. 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.

enter image description here

How can I fail the build?

Upvotes: 3

Views: 137

Answers (1)

trampster
trampster

Reputation: 8898

The following code will cancel the build.

DTE dte = (DTE)GetService(typeof(DTE));
dte.ExecuteCommand("Build.Cancel");

Upvotes: 1

Related Questions