[ACCEPTED]-Display a message in Visual Studio's output window when not debug mode?-visual-studio
The results are not in the Output window 4 but in the Test Results Detail (TestResult 3 Pane at the bottom, right click on on Test 2 Results and go to TestResultDetails).
This 1 works with Debug.WriteLine and Console.WriteLine.
The Trace messages can occur in the output 3 window as well, even if you're not in debug 2 mode. You just have to make sure the the 1 TRACE compiler constant is defined.
The Trace.WriteLine method is a conditionally 9 compiled method. That means that it will 8 only be executed if the TRACE constant is 7 defined when the code is compiled. By default 6 in Visual Studio, TRACE is only defined 5 in DEBUG mode.
Right Click on the Project 4 and Select Properties. Go to the Compile 3 tab. Select Release mode and add TRACE 2 to the defined preprocessor constants. That 1 should fix the issue for you.
This whole thread confused the h#$l out 11 of me until I realized you have to be running the debugger to see ANY trace or debug output. I needed a debug 10 output (outside of the debugger) because 9 my WebApp runs fine when I debug it but 8 not when the debugger isn't running (SqlDataSource 7 is instantiated correctly when running through 6 the debugger).
Just because debug output 5 can be seen when you're running in release 4 mode doesn't mean you'll see anything if you're 3 not running the debugger. Careful reading 2 of Writing to output window of Visual Studio? gave me DebugView as an alternative. Extremely useful!
Hopefully 1 this helps anyone else confused by this.
For me this was the fact that debug.writeline 11 shows in the Immediate window, not the Output. My 10 installation of VS2013 by default doesn't 9 even show an option to open the Immediate 8 window, so you have to do the following:
Select Tools -> Customize
Commands Tab
View | Other Windows menu bar dropdown
Add Command...
The Immediate option is in the Debug section.
Once 7 you have Ok'd that, you can go to View -> Other 6 Windows and select the Immediate Window 5 and hey presto all of the debug output can 4 be seen.
Unfortunately for me it also showed 3 about 50 errors that I wasn't aware of in 2 my project... maybe I'll just turn it off 1 again :-)
To write in the Visual Studio output window 7 I used IVsOutputWindow
and IVsOutputWindowPane
. I included as members in my 6 OutputWindow
class which look like this :
public class OutputWindow : TextWriter
{
#region Members
private static readonly Guid mPaneGuid = new Guid("AB9F45E4-2001-4197-BAF5-4B165222AF29");
private static IVsOutputWindow mOutputWindow = null;
private static IVsOutputWindowPane mOutputPane = null;
#endregion
#region Constructor
public OutputWindow(DTE2 aDte)
{
if( null == mOutputWindow )
{
IServiceProvider serviceProvider =
new ServiceProvider(aDte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
mOutputWindow = serviceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
}
if (null == mOutputPane)
{
Guid generalPaneGuid = mPaneGuid;
mOutputWindow.GetPane(ref generalPaneGuid, out IVsOutputWindowPane pane);
if ( null == pane)
{
mOutputWindow.CreatePane(ref generalPaneGuid, "Your output window name", 0, 1);
mOutputWindow.GetPane(ref generalPaneGuid, out pane);
}
mOutputPane = pane;
}
}
#endregion
#region Properties
public override Encoding Encoding => System.Text.Encoding.Default;
#endregion
#region Public Methods
public override void Write(string aMessage) => mOutputPane.OutputString($"{aMessage}\n");
public override void Write(char aCharacter) => mOutputPane.OutputString(aCharacter.ToString());
public void Show(DTE2 aDte)
{
mOutputPane.Activate();
aDte.ExecuteCommand("View.Output", string.Empty);
}
public void Clear() => mOutputPane.Clear();
#endregion
}
If you have 5 a big text to write in output window you 4 usually don't want to freeze the UI. In 3 this purpose you can use a Dispatcher
. To write something 2 in output window using this implementation 1 now you can simple do this:
Dispatcher mDispatcher = HwndSource.FromHwnd((IntPtr)mDte.MainWindow.HWnd).RootVisual.Dispatcher;
using (OutputWindow outputWindow = new OutputWindow(mDte))
{
mDispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
outputWindow.Write("Write what you want here");
}));
}
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.