Open NogginBops opened 1 week ago
@NogginBops I'm seeing that when starting debugging in Visual Studio, the default working directory is set to the directory of the csproj
file. This is the same as what happens with VS Code debug launch.
If you want to switch the directory used, you can set workingDirectory
in your launchSettings.json
to the profile you are launching.
See https://code.visualstudio.com/docs/csharp/debugger-settings#_cwd
I'm seeing that when starting debugging in Visual Studio, the default working directory is set to the directory of the csproj file.
How are you getting this behaviour? I've been using Visual Studio for many years and in my mind it's common knowledge that the working directory when starting a project in VS is the directory where the final exe file is. And that and directories and files in your project file structure will not be accessible with relative paths unless you explicitly copy them to the output directory.
I can put together a small repro guide if needed but this has been the default behavior of VS for many years. At least in all the circles I've been in.
If you want to switch the directory used, you can set workingDirectory in your launchSettings.json to the profile you are launching.
The problem here is that there is no launch.json
, I'm using the "built-in" run targets provided by the c# devkit and from what I can see the configuration of these targets are not part of any file in my project.
@NogginBops Ah, I made a mistake by testing a Web project instead of a Console project. For Console Projects it is the binary directory, for Web Project it sets it to the project directory.
The issue here is that the project system provides the directory that the debugger should start the target application in.
The suggestion below is a workaround for now as we work on resolving this issue.
If you want to switch the directory used, you can set workingDirectory in your launchSettings.json to the profile you are launching.
The problem here is that there is no launch.json, I'm using the "built-in" run targets provided by the c# devkit and from what I can see the configuration of these targets are not part of any file in my project.
Clarification here is the launchSettings.json
not launch.json
. This would be the file that exists under
With the contents as:
{
"profiles": {
"ConsoleApp": {
"commandName": "Project",
"workingDirectory": "C:\\src"
}
}
}
launchSettings.json
is created/modified in VS if you add commandline arguments or modify the working directory.
Ok yeah I tried launchSettings.json
and that seemed to work as a workaround.
Is there a way to define relative paths in the file? And is it possible to define different paths for Debug and Release?
You can also try override the OutDir
property in your .csproj. This bug seems to be caused by a mixture use of forward/backward slash in OutDir
.
<PropertyGroup>
<OutDir>bin/$(Configuration)/$(TargetFramework)</OutDir>
</PropertyGroup>
Describe the Issue
The default C# run targets don't correctly set the working directory of the spawned process to the
bin/Debug/net8.0/
folder where the executable is located.The causes problems when using relative paths to access files in the output directory, and it's the expected working directory when working with Visual Studio on windows.
It would be nice if it was possible to have a setting to get the Visual Studio behaviour instead of the current behaviour.
Steps To Reproduce
Directory.GetCurrentDirectory()
.Expected Behavior
The same as VIsual Studio. The working directory should be
bin/Debug/net8.0/
.Environment Information
Ubuntu 22.04 LTS C# devkit v1.12.37 (pre-release) C# (extension) v2.50.27 .NET Install Tool v2.2.2