How can I override every possible Before Build Event, and cancel it? Restarting the build later is working fine

207 Views Asked by At

In my extension I also have builder functionality that build additional projects and solutions after or before Visual Studio built the current solution. So when I build the additional projects I have to block any attempt for the user to accidentially build the current solution, or any of the projects. It has to wait.

The following code works well, but it doesn't seem to block the build when I right-click on a project in solution explorer, and click Build or Rebuild from that pop-up menu.

private void OverrideBuildCommands()
{
    /* this I can cancel/restart */
    BuildCommandEvents = DTE.Events.CommandEvents["{5EFC7975-14BC-11CF-9B2B-00AA00573819}", 882];
    BuildCommandEvents.BeforeExecute += BuildCommandEvents_BeforeExecute;
    BuildCommandEvents.AfterExecute += BuildCommandEvents_AfterExecute;

    BuildEvents = DTE.Events.BuildEvents;
    DTE.Events.BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
    DTE.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone;
    DTE.Events.BuildEvents.OnBuildProjConfigBegin += BuildEvents_OnBuildProjConfigBegin;
    DTE.Events.BuildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone;

    /* this I can cancel/restart */
    RebuildCommandEvents = DTE.Events.CommandEvents["{5EFC7975-14BC-11CF-9B2B-00AA00573819}", 883];
    RebuildCommandEvents.BeforeExecute += RebuildCommandEvents_BeforeExecute;
    RebuildCommandEvents.AfterExecute += RebuildCommandEvents_AfterExecute;

    DTEEvents = DTE.Events.DTEEvents;
    DTE.Events.DTEEvents.OnBeginShutdown += DTEEvents_OnBeginShutdown_CancelBuild;
}

Any help or pointer would be appreciated.

1

There are 1 best solutions below

1
On BEST ANSWER

Using the Enable VSIP Logging feature, included with Mad's ExtensibilityTools extension, you can readily identify the command id's, by holding down the CTRL+SHIFT keys when selecting the Build or Rebuild commands in question.

It appears the Build and Rebuild commands on the project node's context menu are 892, and 893 respectively. I suspect if you add Before/AfterExecute events for those commands as well, that'll fix you up.

Sincerely,