Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding current directory during Visual Studio debugging session?

Tags:

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

like image 907
Peter Mortensen Avatar asked Sep 02 '09 13:09

Peter Mortensen


People also ask

Where is the Visual Studio working directory?

Open Project -> Properties -> Configuration Properties -> Debugging . The working directory entry is $(ProjectDir) by default.

How do I change the working directory in Visual Studio?

In Visual Studio 2010: Go to the project properties (rigth click on the project name in the Solution Explorer, then Properties on the pop up menu). Then, under Configuration Properties / Debugging, set Working Directory to $(SolutionDir)$(Configuration)\ .

How do I set Debug path in Visual Studio?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).

How can I see debugging variables?

When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.


2 Answers

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

System.IO.Directory.GetCurrentDirectory()
like image 111
Philip Rieck Avatar answered Oct 21 '22 12:10

Philip Rieck


Within your code, call the function

System.IO.Directory.GetCurrentDirectory()

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).

like image 28
Richard Avatar answered Oct 21 '22 12:10

Richard