Differences in a program's directory between vs and vs code

Viewed 63

I am making a program that involves looking for a program's directory. I was making this in visual studio, until today, where I decided to try visual studio code.

Immediately I ran into an issue, with the program not being able to find a file that it should open. I am using Path.GetDirectory() to find the location of the program and using that and combining it with the path to a text file in order to open the said text file

After doing a bit of testing, I found that in vs code the directory it uses to run the program to the directory in visual studio. (Visual Studio uses the location of the .exe file while Visual Studio Code uses the program.cs file directory)

So does anyone have any ideas as to why visual studio code uses a different directory compared to the visual studio? And is there a way for the program to always look for the .exe file over the .cs file

1 Answers

Well, I'm not sure why it is that these are the defaults, though I imagine it is because VS Code is more focused on quick development, while Visual Studio is more focused on production development, but I do know how to change them. In Visual Studio, right click (or Alt+Enter) on the project, go to the Debug tab, and change the working directory field.

In VS Code, go ahead and change the "cwd" field in launch.json to whatever you want it to be. You can use these variables in there.

Visual Guide for Visual Studio:
Project

Properties

Go to Debug

Change working directory

Related