-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix dotnet run to accept Windows path separators on Linux #50889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: marcpopMSFT <[email protected]>
@baronfel @jjonescz @marcpopMSFT Is this expectation really correct? I was expecting this should actually fail (in my view, both separators should work on Windows, but only |
It is a regression, so that might be a good reason to continue supporting it. (I personally don't mind if we break this either.) Otherwise I agree that it's fine when |
|
||
// Normalize path separators to handle Windows-style paths on non-Windows platforms | ||
// First convert backslashes to forward slashes on non-Windows, then get the full path | ||
if (Path.DirectorySeparatorChar != '\\') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment that we only support this for historical reasons to avoid a break. We probably don't strive to support \
on Linux in all path arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case yeah let's not support that in dotnet test.
A comment would help.
FYI, this targets main. And Copilot PRs don't seem to get the automatic comment about the branch. |
A regression from a preview feature is hard to balance if we should keep this. The feedback came from a customer using the feature though. @baronfel as this is a bit of a business decision as to whether it's better to error as expected or accept this for better compat. |
I'm mostly wondering three things:
|
Backslash is a valid filename character on Unix so this would break that case. |
The
dotnet run
command fails on Linux when provided with Windows-style path separators (backslashes), breaking cross-platform PowerShell scripts and mixed development environments.Problem
After PR #49544 added file existence validation, the following command fails on Linux:
With error:
While the equivalent with forward slashes works correctly:
This regression breaks PowerShell scripts that use Windows-style paths and expect them to work cross-platform.
Solution
Added path separator normalization in
RunCommand.DiscoverProjectFilePath()
to convert Windows-style backslashes to forward slashes on non-Windows platforms before checking file existence:Testing
.\src\MyProject\MyProject.csproj
correctly normalizes to./src/MyProject/MyProject.csproj
on LinuxThe fix is minimal, platform-aware, and preserves all existing behavior while enabling cross-platform compatibility for Windows-style paths.
Fixes #50828.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.