I no longer work at Microsoft, so please don't bother leaving a comment here or trying to contact me through my MSDN blog.
You can find my new blog at http://www.technologytoolbox.com/blog/jjameson. My new site also provides copies of all posts from my MSDN blog.
As I mentioned in a post last week, I often use macros in Visual Studio to automate development tasks.
Before sharing some of my most frequently used macros, however, I wanted to first introduce the method I use to trace events and log messages while running various macros.
Take a look at the following Output window from Visual Studio. Notice how there is an item in the Show output from dropdown list titled Macros (a.k.a. "the macro output pane").
Chances are that when you look at your Visual Studio environment, you won't see this item. So, why does it appear in my environment?
The macro output pane is actually created on-the-fly, as necessary, whenever I run one of my macros that implements tracing (i.e. writes output). This is done via the GetMacroOutputPane() function, as shown below.
Private Function GetMacroOutputPane() As OutputWindowPane
Dim ow As OutputWindow = _
Dim outputPane As OutputWindowPane
outputPane = ow.OutputWindowPanes.Item("Macros")
Catch ex As Exception
outputPane = ow.OutputWindowPanes.Add("Macros")
Pretty simple, eh? If the macro output pane exists, then use it; otherwise add a new pane.
In order to simplify writing output messages -- as well as timestamp each message as it is written -- I use the WriteOutput() method
Private Sub WriteOutput( _
ByVal s As String)
Dim buffer As StringBuilder = New StringBuilder
Dim output As String = buffer.ToString()
Dim outputPane As OutputWindowPane = GetMacroOutputPane()