在VS中,使用控制台进行断点打印
我在 VS 2010 中设置了一个“点击时打印消息”断点。它可以工作,但它只输出到 VS“输出”窗格。我可以让它使用我的应用程序的控制台窗口吗?
我尝试过:
Debug.Listeners.Add(new ConsoleTraceListener());
以及:
var writer = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(writer);
I've made a "when hit, print a message" breakpoint in VS 2010. It works, but it only outputs to the VS "output" pane. Can I make it use my app's console window?
I've tried:
Debug.Listeners.Add(new ConsoleTraceListener());
As well as:
var writer = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(writer);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以在应用程序控制台窗口中打印此消息,但为此您需要使用调试器评估器:
看一下这段代码:
如果您在第 5 行放置一个断点:Console.WriteLine(i); 并设置了 When Hit... 属性to: {MessageFromDebugger("message from address $ADDRESS")} 您应该在控制台窗口中看到:
有趣的是,您可以将在调用范围内有效的参数传递给函数特别的调试器变量(例如 $ADDRESS、$PID、$CALLSTACK 等)。我观察到特殊的调试器变量只是占位符,并且在提交到函数之前被替换,所以请记住将它们放在双引号中,例如。 {MessageFromDebugger(@"$CALLSTACK")}
It is possible to print this message in your app console window, but for that you need to use the debugger evaluator:
Have a look at this code:
If you place a breakpoint on line 5: Console.WriteLine(i); with When Hit... property set to: {MessageFromDebugger("message from address $ADDRESS")} you should see in your console window:
What's interesting is that you may pass arguments to your function that are valid in the calling scope as well as the special debugger variables (such as $ADDRESS, $PID, $CALLSTACK etc.). I observed though that special debugger variables are just placeholders and are replaced before submitting to your function, so remember to put them in double quotes, eg. {MessageFromDebugger(@"$CALLSTACK")}