Immediate Window automatic cleaning in Visual Studio
Asked Answered
O

1

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.

Ovalle answered 25/2, 2010 at 12:37 Comment(0)
E
10

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.

Engineer answered 25/2, 2010 at 15:41 Comment(5)
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.Ovalle
Did you place it in EnvironmentEvents module? There should be autogenerated region with correcr variable definition: <System.ContextStaticAttribute()> Public WithEvents BuildEvents As EnvDTE.BuildEvents Insert the macro after this region. I'll update mu answer with the screenshotEngineer
I've missed it at the ending of the work day. ))) Thank you, Peter! :)Ovalle
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.Pusillanimity
that should have been can't believe.Pusillanimity

© 2022 - 2024 — McMap. All rights reserved.