在 Visual Studio 调试会话期间查找当前目录?
如何找到 .NET 应用程序的当前目录 在 Visual Studio 调试器下运行?
更新 1。需要明确的是:我不想更改代码 或获取程序本身的信息 - 我只是想 获取当前正在运行的应用程序的信息 已调试。
调试 .NET Windows 窗体 应用程序时(混合 VB.NET 和 C#)我不确定 XML 文件来自哪个位置 读自。我期望当前目录是 应用程序的目录。但是,使用 Process Explorer, 该过程的属性导致:
D:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\
(右键单击进程/属性/选项卡图像/当前目录)。
将光标悬停在 Process Explorer 主视图中的流程上 显示了不同的结果(请参见下面的屏幕截图):
D:\dproj\DTASCall\DTASuperCharge\bin\
什么是正确的?
独立启动应用程序会显示预期的结果 当前目录,
D:\dproj\DTASCall\DTASuperCharge\bin\
Process Explorer 进程属性窗口中的
。带注释的 Process Explorer 屏幕截图:
替代文本 http ://www.pil.sdu.dk/1/until2039-12-31/PEdiscrepancy_2009-09-02.png
How can I find the current directory for a .NET application
running under the Visual Studio debugger?
Update 1. To be clear: I don't want to change the code
or get information in the program itself - I just want to
get information about the application currently being
debugged.
While debugging a .NET Windows Forms application (mixed VB.NET and
C#) I was not sure from which location a XML file was being
read from. I expected the current directory to be the
application's directory. However, using Process Explorer,
properties for the process result in:
D:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\
(right click on process/Properties/tab Image/Current Directory).
Hovering the cursor over the process in the main view of Process Explorer
revealed a different result (see below for a screenshot):
D:\dproj\DTASCall\DTASuperCharge\bin\
What is correct?
Starting the application standalone displays the expected
current directory,
D:\dproj\DTASCall\DTASuperCharge\bin\
in the Process Explorer process properties window.
Annotated screen-shot of Process Explorer:
Alt text http://www.pil.sdu.dk/1/until2039-12-31/PEdiscrepancy_2009-09-02.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Visual Studio 中,在调试选项卡中的项目设置下,您可以根据需要设置“工作目录”。
要确定代码中或断点中的立即窗口中的当前工作目录,请尝试
In Visual Studio, under the project's settings in the debug tab, you can set the "Working Directory" if you want.
To determine the current working directory in code or in the immediate window in a breakpoint, try
在代码中,调用该函数
默认情况下,除非您更改了项目的“调试”属性,否则当前目录将作为项目的 bin\Debug 目录(.exe 从中运行)开始。
Within your code, call the function
By default, unless you've changed the Debug properties of your project, the current directory will start as the bin\Debug directory of your project (where the .exe runs from).
最好的方法是在 WinDbg(Windows 调试器)中运行应用程序,然后附加到处理并运行
!handle
命令。每个打开的文件都有一个关联的句柄。通过转储相应进程的所有句柄,您将看到相应的文件路径。下面是一个示例:
将 process-id 替换为您的进程 ID 的值。您还可以使用进程地址来代替进程 ID。如果这没有显示文件对象,则文件句柄已经关闭。在这种情况下,您需要追踪手柄。这可以通过
!htrace
命令来完成。The best way is to run the application in WinDbg (the Windows debugger), then attach to the process and run the
!handle
command. Each open file will have an associated handle. By dumping all the handles for the corresponding process, you will see the corresponding file path.Here is an example:
Replace the process-id with the value of your process id. In place of the process id you can also use the process address. If this does not show the file object, then file handle has already been closed. In this case you need to trace the handles. This can be done with the
!htrace
command.