I'm trying to log output to the Output window from one of my macros in Visual Studio. I thought that Debug.Print would do the trick like it does in Visual Basic.NET and VBA, but it doesn't do that.
I found this, and tried this, it is not simple, nor does it work in Visual Studio 2005 (see bellow):
Private Function GetMacroOutputPane() As OutputWindowPane
Dim ow As OutputWindow = _
DTE.Windows.Item(Constants.vsWindowKindOutput).Object()
Dim outputPane As OutputWindowPane
Try
outputPane = ow.OutputWindowPanes.Item("Macros")
Catch ex As Exception
outputPane = ow.OutputWindowPanes.Add("Macros")
End Try
Return outputPane
End Function
Private Sub WriteOutput( _
ByVal s As String)
Dim buffer As String
buffer = buffer & Date.Now.ToLongTimeString()
buffer = buffer & " "
buffer = buffer & s
buffer = buffer & vbCrLf
Dim output As String = buffer.ToString()
Dim outputPane As OutputWindowPane = GetMacroOutputPane()
outputPane.OutputString(output)
End Sub
See the Output error below:
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IndexOutOfRangeException' occurred in VBAssembly
The thread 0x23e4 has exited with code 0 (0x0).
The thread 0x1118 has exited with code 0 (0x0).
'vsmsvr.exe' (Managed): Loaded 'C:\Windows\assembly\GAC\EnvDTE80\8.0.0.0__b03f5f7f11d50a3a\EnvDTE80.dll', No symbols loaded.
'vsmsvr.exe' (Managed): Loaded 'C:\Windows\assembly\GAC\EnvDTE80\8.0.0.0__b03f5f7f11d50a3a\EnvDTE80.dll', No symbols loaded.
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
'vsmsvr.exe' (Managed): Loaded 'C:\Windows\assembly\GAC\EnvDTE80\8.0.0.0__b03f5f7f11d50a3a\EnvDTE80.dll', No symbols loaded.
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.Exception' occurred in VBAssembly
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Is there any simple way to do this? I'm sick of having to popup a message box (mainly because when you run the script it you have to click ok a zillion times) when I just want some simple console output that I can look at.