views:

299

answers:

1

Hi.

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.

+1  A: 

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.

Peter Macej
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
Did you place it in EnvironmentEvents module? There should be autogenerated region with correcr variable definition:<System.ContextStaticAttribute()> Public WithEvents BuildEvents As EnvDTE.BuildEventsInsert the macro after this region. I'll update mu answer with the screenshot
Peter Macej
I've missed it at the ending of the work day. ))) Thank you, Peter! :)
Lyubomyr Shaydariv