Visual Studio macro to hide/show the Output window after a build…
I do not like the behaviors allowed in Visual Studio regarding showing the Errors List and Output window during a build. So, I finally created a macro to get the exact behavior I want.. And, I love it!
First off, you need to turn off two options in Visual Studio settings, under Projects and Solutions | General.
Un-check the following:
- Always show Error List if build finishes with errors
- Show Output window when build starts
The script does the following:
- When a build starts it (optionally) shows the Output window (line #9).
- When an individual project is finished compiling, notify the user (line #22) and (optionally) stop building any further projects (line #25).
- When the entire build has finished and one or more projects failed, display the Output window (line #35). If there were no failures, show and then hide the Output window (line #38) and notify the user.
Note: When the build finishes successfully, the reason I show and then hide the Output window, is because it may already be open and I want to be sure I close it. So far, I haven’t found an easy way to close the Output window, when it may or may not have focus in the Visual Studio IDE. As it is, I only rarely see it flicker open then closed. If you have any ideas, please let me know at kody@bricksoft.com!
Read the comments in the code below for details on how its done!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | Private BuildFailed As Boolean = False ' The build has started. ' Could be one or more projects or the whole solution. Private Sub BuildEvents_OnBuildBegin() Handles BuildEvents.OnBuildBegin ' Reset the global flag. BuildFailed = False ' Optionally, show the Output window. 'DTE.ExecuteCommand("View.Output") End Sub ' The current project has finished building. Private Sub BuildEvents_OnBuildProjConfigDone( ByVal Project As String, ByVal ProjectConfig As String, _ ByVal Platform As String, ByVal SolutionConfig As String, _ ByVal Success As Boolean) _ Handles BuildEvents.OnBuildProjConfigDone If (Not Success) Then ' Set the global flag. BuildFailed = True ' Notify the user the build failed. NotifySuccess(False) ' Optionally, you can cancel any further project builds. 'DTE.ExecuteCommand("Build.Cancel") End If End Sub ' The build is finished. Show or hide the Output window based on ' whether it was successful or not. Private Sub BuildEvents_OnBuildDone( ByVal Scope As EnvDTE.vsBuildScope, _ ByVal Action As EnvDTE.vsBuildAction) _ Handles BuildEvents.OnBuildDone If BuildFailed Then ' Show the output window. DTE.ExecuteCommand("View.Output") Else ' The build succeeded, so hide the Output window. DTE.ExecuteCommand("View.Output") DTE.ExecuteCommand("Window.CloseToolWindow") ' Notify the user the build finished successfully. NotifySuccess(True) End If End Sub Private Sub NotifySuccess(ByVal Success As Boolean) If Success Then Beep() Threading.Thread.Sleep(250) Beep() Else Beep() Threading.Thread.Sleep(250) Beep() Threading.Thread.Sleep(250) Beep() Threading.Thread.Sleep(250) Beep() End If End Sub |