8

I have a question about debugging in Visual Studio. Is it possible to clear the Immediate Window in Visual Studio automatically before each startup of a debugged application? The >cls command and Context Menu->Clear All are useful, but they are not automatic and require personal attention each time I run the application. Again, System.Diagnostics.Debug.Print()|Write*() methods can only write messages to the Immediate Window, so >cls is not applicable. Is there any solution for the problem? (Currently I use VS 2008)

Thank you for suggestions.

Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105

1 Answers1

9

Here is the macro that does it. In the Macros IDE Class View navigate to MyMacros - EnvironmentEvents. Open (double-click) EnvironmentEvents. Insert the following code inside module:

Private Sub BuildEvents_OnBuildDone( _
    ByVal Scope As EnvDTE.vsBuildScope, _
    ByVal Action As EnvDTE.vsBuildAction) _
    Handles BuildEvents.OnBuildDone

    Try
        Dim activeWin As Window = DTE.ActiveWindow
        Dim immedWin As Window = DTE.Windows.Item("{ECB7191A-597B-41F5-9843-03A4CF275DDE}")
        immedWin.Activate()
        DTE.ExecuteCommand("Edit.ClearAll")
        activeWin.Activate()
    Catch ex As Exception
    End Try
End Sub

Here you can see how it should look like: macro in EnvironmentEvents

See my quick tutorial how to create and execute VS macro.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Peter Macej
  • 4,831
  • 22
  • 49
  • Thank you for reply, Peter. I've tried your code in VS Macros, but I've got an error _"Handles clause requires a WithEvents variable defined in the containing type or one of its base types."_ in line *Handles BuildEvents.OnBuildDone* with BuildEvents object. Unfortunately I'm not very familiar with VB.NET. – Lyubomyr Shaydariv Feb 25 '10 at 16:38
  • 1
    Did you place it in EnvironmentEvents module? There should be autogenerated region with correcr variable definition: Public WithEvents BuildEvents As EnvDTE.BuildEvents Insert the macro after this region. I'll update mu answer with the screenshot – Peter Macej Feb 25 '10 at 19:20
  • I've missed it at the ending of the work day. ))) Thank you, Peter! :) – Lyubomyr Shaydariv Feb 26 '10 at 09:33
  • Exactly what I wanted and it only took 5 seconds go googling to find it. I can believe you only have one vote for this. – Tim Murphy Dec 18 '10 at 11:49
  • that should have been can't believe. – Tim Murphy Dec 18 '10 at 14:00