einaregilsson / StopOnFirstBuildError

Visual Studio extension to stop solution build immediately after a projects fails to build.
http://einaregilsson.com/stop-build-on-first-error-in-visual-studio-2010/
51 stars 17 forks source link

Patch for duplicate Build.Cancel events #4

Closed tekskater closed 10 years ago

tekskater commented 10 years ago

Hi,

I am using your nice extension with Visual Studio 2012, but I find that Visual Studio often hangs if I manually cancel a parallel build that has errors because the StopOnFirstBuildError extension does not realize that the build was already canceled and tries to cancel it a second time. Here is a patch to StopOnFirstBuildErrorPackage.cs that fixes this problem by ensuring that Build.Cancel is only invoked once:

56a57

    private CommandEvents _buildCancel;

141a143,147 //Following on from above, we need to intercept the Build.Cancel command to ensure that we only execute it once. const string VSStd97CmdIDGuid = "{5efc7975-14bc-11cf-9b2b-00aa00573819}"; _buildCancel = _dte.Events.get_CommandEvents(VSStd97CmdIDGuid, (int)VSConstants.VSStd97CmdID.CancelBuild); _buildCancel.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(buildCancel_BeforeExecute);

180,181d185 < _canExecute = false; < 198a203,217 private void buildCancel_BeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault) { if (Active && Enabled) { // Ensure that we only execute Build.Cancel once since executing it multiple times sometimes causes VS 2012 // to hang when running a parallel build. if (_canExecute) // Let Build.Cancel run this time. _canExecute = false; else // Build has already been canceled, so don't try to cancel it again. CancelDefault = true; } }

Thanks.

einaregilsson commented 10 years ago

Thanks for the patch. I'll try to get it merged, tested and publish sometime this week.

tekskater commented 10 years ago

That would be great. Thanks, and sorry for the primitive form of patch delivery.

einaregilsson commented 10 years ago

Well, it's in. Try downloading v1.4 and see if it works for you. Thanks again.

tekskater commented 10 years ago

It doesn't look like the patch was merged correctly. The "_canExecute = false;" at line 204 needs to be deleted otherwise the extension won't actually cancel the build if there is a failure.

tekskater commented 10 years ago

It probably does not matter, but I had originally put lines 138 - 140 after line 145 (i.e. so that we don't add the new BeforeExecute handler for Build.Cancel until after we've added the handlers for OnBuildBegin and OnBuildDone).

tekskater commented 10 years ago

Just to be clear, my version looks like:

        //Since Visual Studio 2012 has parallel builds, we only want to cancel the build process once.
        //This makes no difference for older versions of Visual Studio.
        _buildEvents.OnBuildBegin += delegate { _canExecute = true; };
        _buildEvents.OnBuildDone += delegate { _canExecute = false; };

        //Following on from above, we need to intercept the Build.Cancel command to ensure that we only execute it once.
        const string VSStd97CmdIDGuid = "{5efc7975-14bc-11cf-9b2b-00aa00573819}";
        _buildCancel = _dte.Events.get_CommandEvents(VSStd97CmdIDGuid, (int)VSConstants.VSStd97CmdID.CancelBuild);
        _buildCancel.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(buildCancel_BeforeExecute);