By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

Cannot stop command line build from AddIn

P: n/a
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.OnBuildProjCo nfigDone += 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

Sep 15 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.OnBuildProjCo nfigDone += 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
AlexZh wrote:
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.OnBuildProjCo nfigDone += 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
Sep 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.