Cannot stop command line build from AddIn

A

AlexZh

Hi, I'd like to stop command line build by one project build failed.
To do that I've created simple AddIn (see code below), that works fine
for IDE and does not work for command line.
In the AddIn I have only two non-trivial methods:
In OnConnection I add my event handler to OnBuildProjConfigDone, and in
the event handler I executed Build.Cancel.
In IDE - no problem.
When I execute
devenv /build mySolution
I see that AddIn works and Build.Cancel is called but the build is
still going.
What I do wrong? Maybe DTE.ExecuteCommand(...) waits for the end of
build in that mode...
Does anybody know how to make DTE.ExecuteCommand executes at the moment
of a call.

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
applicationObject = (_DTE)application;
addInInstance = (AddIn)addInInst;
applicationObject.Events.BuildEvents.OnBuildProjConfigDone += new

_dispBuildEvents_OnBuildProjConfigDoneEventHandler(BuildEvents_OnBuildProjConfigDone);
}

public void BuildEvents_OnBuildProjConfigDone(string project, string
projectConfig, string platform, string solutionConfig, bool success)
{
if( !success )
{
applicationObject.DTE.ExecuteCommand("Build.Cancel", "");
}
}

Thank you,
Alex
 
A

AlexZh

Hi. I did not received a reply but for those who is interested in this
subject I've found an answer.
The problem is: how to stop a solution build when a project build
failed. It must be done for IDE build and for command line build as
well.

It could be done with a simple AddId (for my I use C#).

For some reason applicationObject.Events.BuildEvents objects could not
be used in "direct" way. You must keep reference to it in a Connect
class scope. Since I keep a reference to a applicationObject, it looks
strange. It looks like applicationObject keeps a weak reference to
applicationObject.Events.BuildEvents... Anyway if you define
BuildEventsClass bec;
in a class scope (not in a method!) and add
bec = applicationObject.Events.BuildEvents as BuildEventsClass;
to OnConnection(...) methods, all the build events work fine.

For unknown for me reasons
applicationObject.DTE.ExecuteCommand("Build.Cancel", "");
does not work also for a command line build. So, I use cpp exit()
method for command line build and "Build.Cancel" for IDE build.
To do that you must also know the mode your application works in: IDE
or CommandLine.

Below are code snippets:
public class Connect : Object, Extensibility.IDTExtensibility2
{
[DllImport("msvcr71.dll")]
public static extern void exit(int exitCode);

bool isCommandLineMode = false;
private _DTE applicationObject;
private AddIn addInInstance;
BuildEventsClass bec;

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
applicationObject = (_DTE)application;
addInInstance = (AddIn)addInInst;
isCommandLineMode = (connectMode ==
Extensibility.ext_ConnectMode.ext_cm_CommandLine);
bec = applicationObject.Events.BuildEvents as BuildEventsClass;
//must
applicationObject.Events.BuildEvents.OnBuildProjConfigDone += new
_dispBuildEvents_OnBuildProjConfigDoneEventHandler(BuildEvents_OnBuildProjConfigDone);
}

public void BuildEvents_OnBuildProjConfigDone(string project, string
projectConfig, string platform, string solutionConfig, bool success)
{
if( !success )
{
if( isCommandLineMode )
{
exit(-5);
}
else
{
applicationObject.DTE.ExecuteCommand("Build.Cancel", "");
}
}
}
}

I still don't know how to do the same with IDE macro instead of AddIn.
Regards,
Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top