将监视的Visual Studio变量输出到文件 [英] Output a watched Visual Studio variable to a file

查看:290
本文介绍了将监视的Visual Studio变量输出到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio(如果需要的话,2008年)中是否有一种方法可以在调试/中断模式下将变量的内容写入文本/XML文件?

Is there a way in Visual Studio (2008 if it matters) that I can, in debug/break mode, write the contents of a variable to a text/XML file?

这种情况是,我在调试中运行的过程很长,而我意识到为时已晚,因为我没有记录有关该进程正在监视的事件的足够详细信息,但是幸运的是,在代码.

The scenario is that I have a long process running in debug and I have realised too late that I haven't logged enough detail about the events that the process has been monitoring, but fortunately a history is still available within a variable in the code.

我可以在此列表中浏览成千上万的项目,但是一旦我在应用程序上按一下stop,它就不会持续下去……没有明显的上下文选项,但是有什么办法,那就更好了比手动方式?还是没有希望,我只需要按一下停止按钮,重新设置日志记录功能,然后再次运行它就可以了?

I could trawl through the tens of thousands of items in this list, but it's not going to persist once I hit stop on the application ... there is no obvious context option for this, but is there any way, a better way than manual? Or is there no hope and I just need to hit stop, re-tool the logging function and run the thing again?

除了尝试达到断点,修改代码并重新编写以使记录器更好之外,还有没有一种方法可以不丢失内存中的数据?

Aside from trying to hit a breakpoint, modify the code and re-write to make a better logger, is there a way of not losing that in-memory data?

推荐答案

一种方法是使用即时窗口(菜单 Debug -> Windows - > 立即).在出现的窗口中,您可以使用?"查询变量的值.

One way to do it would be to use the immediate window (menu Debug -> Windows -> Immediate). In the window that appears you can use the "?" to query the value of a variable.

假设您的历史记录变量是一个字符串,则可以通过在立即窗口中键入以下内容来查看其内容:

Assuming your history variable is a string you view its contents by typing the following in the immediate window:

?history

您可以将输出复制并粘贴到文本文件中,或者要求Visual Studio记录所有命令窗口的输出.为此,请执行以下操作:

You could copy and paste the output from there into a text file or alternatively ask Visual Studio to log all command window output. To do this type:

>log "c:\test.log"
?history
>log off

LogTools.LogCommandWindowOutput的别名,并接受以下参数:

Log is an alias for Tools.LogCommandWindowOutput and accepts the following parameters:

Tools.LogCommandWindowOutput [filename] [/on|/off] [/overwrite]

查看MSDN文章 日志命令窗口输出命令" 了解更多信息.

Check out the MSDN article Log Command Window Output Command for more information.

这篇关于将监视的Visual Studio变量输出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆