Open frankbuckley opened 1 month ago
Workaround to get Visual Studio to behave the same as dotnet run
from the project root is to add "workingDirectory": "./"
to launchSettings.json
:
{
"profiles": {
"CommandLineTest": {
"commandName": "Project",
"commandLineArgs": "--file ./bin/Debug/net8.0/CommandLineTest.runtimeconfig.json",
"workingDirectory": "./"
}
}
}
This works the same in Visual Studio as:
dotnet run -- --file ./bin/Debug/net8.0/CommandLineTest.runtimeconfig.json
Following the getting started tutorial:
and with a
launchSettings.json
:If you start the project from Visual Studio, then it works as expected and writes the contents of the file to the console.
If you **start the built project from the
bin\Debug\net8.0
directory***, then it works as expected and writes the contents of the file to the console.If you start the project using
dotnet run -- --file CommandLineTest.runtimeconfig.json
, then you get an exception:This is due to difference in how current directory is set when running from Visual Studio vs. CLI.
FileInfo
(andDirectoryInfo
) end up using current directory to normalize relative paths.If you add the following lines to
Main()
and run from CLI and Visual Studio you can observe the differences:You might consider updating the getting started docs to note the problem and/or update the path used for the
dotnet run
example - for example:dotnet run -- --file .\bin\Debug\net8.0\CommandLineTest.runtimeconfig.json
Related: