-
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
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.
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.
@copilot add a comment that we're only supporting this for compat for run and not all CLI commands.
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.
Added clarifying comment in commit d72e965 explaining that this path normalization is supported for backward compatibility in dotnet run only, not for all CLI commands.
|
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. |
|
I was also affected by this bug. We previously had various bash/cmd scripts, but we converted everything to PowerShell to support cross-platform compatibility. PowerShell is agnostic about the direction of slashes and just makes it work on all platforms. That used to be the case for Please fix this before the final .NET 10 release. The tooling should remain flexible with inputs, as it has been. Users don't care about the theoretical case where a filename may contain a backslash character. |
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.
Pull Request Overview
This PR fixes a regression in dotnet run where Windows-style path separators (backslashes) were not accepted on Linux systems, breaking cross-platform PowerShell scripts and mixed development environments. The fix normalizes path separators on non-Windows platforms before file existence validation.
Key Changes:
- Added path separator normalization in
RunCommand.DiscoverProjectFilePath()to convert backslashes to forward slashes on non-Windows platforms - Added platform-specific unit tests to verify both Windows and Linux path handling
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Cli/dotnet/Commands/Run/RunCommand.cs | Added path separator normalization logic to handle Windows-style paths on non-Windows platforms |
| test/dotnet.Tests/CommandTests/Run/RunParserTests.cs | Added platform-specific tests for Windows and Linux path separator handling |
|
Thanks for the reminder. It's too late for 10.0.100 but we discussed offline adding it for 2xx just for run for compat. |
…ation Co-authored-by: marcpopMSFT <[email protected]>
|
Why do this for |
|
/backport to release/10.0.2xx |
|
Started backporting to release/10.0.2xx: https://github.com/dotnet/sdk/actions/runs/18764745718 |
Co-authored-by: Copilot <[email protected]>
|
Fix in run for compat reasons only. Don't expand to other commands as they didn't have that behavior before. |
dotnet runfails with Windows path separators (backslashes) on Linux in .NET 10 RC.1DiscoverProjectFilePathmethod inRunCommand.csline 537 whereFile.Exists(projectFilePath)is calledPathUtility.FixFilePathmethod already exists for normalizing path separatorstest/dotnet.Tests/CommandTests/Run/Summary
Problem:
dotnet run --project .\src\MyProject\MyProject.csprojfails on Linux with "The provided file path does not exist"File.Existscheck without normalizing path separators for cross-platform compatibilitySolution Applied:
Added cross-platform path normalization in
RunCommand.DiscoverProjectFilePath()method with clarifying comments that this is supported for backward compatibility indotnet runonly:Testing:
RunParserAcceptsWindowsPathSeparatorsOnLinuxandRunParserAcceptsWindowsPathSeparatorsOnWindows.\src\MyProject\MyProject.csproj→./src/MyProject/MyProject.csprojBehavior:
The fix ensures
dotnet runaccepts Windows-style path separators on Linux for backward compatibility with .NET 9, maintaining cross-platform compatibility for PowerShell scripts and mixed-platform development scenarios. The clarifying comment makes it clear this is intentional fordotnet runonly and not a general pattern for all CLI commands.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.