Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 17, 2025

  • Analyze the issue: dotnet run fails with Windows path separators (backslashes) on Linux in .NET 10 RC.1
  • Locate the problematic code: DiscoverProjectFilePath method in RunCommand.cs line 537 where File.Exists(projectFilePath) is called
  • Find existing utility: PathUtility.FixFilePath method already exists for normalizing path separators
  • Explore test infrastructure: Found existing test structure in test/dotnet.Tests/CommandTests/Run/
  • Create targeted unit tests for the fix
  • Apply minimal fix to normalize project file path before checking existence
  • Run tests to validate the fix
  • Verify the change handles edge cases appropriately
  • Address PR feedback: Add clarifying comment about backward compatibility

Summary

Problem:

Solution Applied:
Added cross-platform path normalization in RunCommand.DiscoverProjectFilePath() method with clarifying comments that this is supported for backward compatibility in dotnet run only:

// Normalize path separators to handle Windows-style paths on non-Windows platforms.
// This is supported for backward compatibility in 'dotnet run' only, not for all CLI commands.
// Converting backslashes to forward slashes allows PowerShell scripts using Windows-style paths
// to work cross-platform, maintaining compatibility with .NET 9 behavior.
if (Path.DirectorySeparatorChar != '\\')
{
    projectFileOrDirectoryPath = projectFileOrDirectoryPath.Replace('\\', '/');
}

Testing:

  • ✅ Added unit tests: RunParserAcceptsWindowsPathSeparatorsOnLinux and RunParserAcceptsWindowsPathSeparatorsOnWindows
  • ✅ All existing RunParser tests pass (8 tests, 1 skipped for Windows-only)
  • ✅ Path normalization validated: .\src\MyProject\MyProject.csproj./src/MyProject/MyProject.csproj
  • ✅ File existence check works correctly after normalization
  • ✅ No regressions introduced - Windows behavior unchanged

Behavior:

  • Before: Windows paths with backslashes fail on Linux
  • After: Windows paths work on both Windows and Linux
  • Forward slash paths continue to work on all platforms
  • Windows-only behavior unchanged (backslashes work natively)

The fix ensures dotnet run accepts 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 for dotnet run only 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.

Copilot AI changed the title [WIP] [10.0-rc.1] dotnet run no longer accepts Windows path separators on Linux Fix dotnet run to accept Windows path separators on Linux Sep 17, 2025
Copilot AI requested a review from marcpopMSFT September 17, 2025 18:42
Copilot finished work on behalf of marcpopMSFT September 17, 2025 18:42
@Youssef1313
Copy link
Member

Youssef1313 commented Sep 18, 2025

This regression breaks PowerShell scripts that use Windows-style paths and expect them to work cross-platform.

@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 / should work for Unix)? Do we need to do any equivalent changes for dotnet test?

@jjonescz
Copy link
Member

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 \ does not work on Linux.


// 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 != '\\')
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@Youssef1313
Copy link
Member

FYI, this targets main. And Copilot PRs don't seem to get the automatic comment about the branch.

@marcpopMSFT
Copy link
Member

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.

@baronfel
Copy link
Member

baronfel commented Sep 18, 2025

I'm mostly wondering three things:

  • is there a BCL API that can normalize this for us
  • can we systematize this so that we auto-normalize wherever we need?
  • are there other places where we're vulnerable to this?

@akoeplinger
Copy link
Member

akoeplinger commented Sep 18, 2025

Backslash is a valid filename character on Unix so this would break that case. I don't think we should be in the business of normalizing paths in the CLI. hmm I just tested and e.g. dotnet build some\folder\app.csproj works and from the original issue it worked in net9 for run too so maybe there are more users that would hit it

@bkoelman
Copy link
Contributor

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 dotnet too, but since RC1, it has broken.

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.

@marcpopMSFT marcpopMSFT marked this pull request as ready for review October 22, 2025 23:48
Copilot AI review requested due to automatic review settings October 22, 2025 23:48
Copy link
Contributor

Copilot AI left a 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

@marcpopMSFT
Copy link
Member

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.

Copilot finished work on behalf of marcpopMSFT October 22, 2025 23:57
@bkoelman
Copy link
Contributor

Why do this for dotnet run, but not for dotnet test?

@marcpopMSFT
Copy link
Member

/backport to release/10.0.2xx

@github-actions
Copy link
Contributor

Started backporting to release/10.0.2xx: https://github.com/dotnet/sdk/actions/runs/18764745718

@marcpopMSFT marcpopMSFT enabled auto-merge October 23, 2025 23:29
@marcpopMSFT
Copy link
Member

Fix in run for compat reasons only. Don't expand to other commands as they didn't have that behavior before.

@marcpopMSFT marcpopMSFT merged commit 65384c6 into main Oct 24, 2025
27 checks passed
@marcpopMSFT marcpopMSFT deleted the copilot/fix-50828 branch October 24, 2025 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[10.0-rc.1] dotnet run no longer accepts Windows path separators on Linux

7 participants