Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Cli/dotnet/Commands/Run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,15 @@ internal static void ThrowUnableToRunError(ProjectInstance project)
projectFileOrDirectoryPath = Directory.GetCurrentDirectory();
}

// 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 != '\\')
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.

{
projectFileOrDirectoryPath = projectFileOrDirectoryPath.Replace('\\', '/');
}

string? projectFilePath = Directory.Exists(projectFileOrDirectoryPath)
? TryFindSingleProjectInDirectory(projectFileOrDirectoryPath)
: projectFileOrDirectoryPath;
Expand Down
28 changes: 28 additions & 0 deletions test/dotnet.Tests/CommandTests/Run/RunParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,33 @@ public void RunParserCanGetArgumentFromDoubleDash()
var runCommand = RunCommand.FromArgs(new[] { "--project", projectPath, "--", "foo" });
runCommand.ApplicationArgs.Single().Should().Be("foo");
}

[WindowsOnlyFact]
public void RunParserAcceptsWindowsPathSeparatorsOnWindows()
{
var tam = new TestAssetsManager(output);
var testAsset = tam.CopyTestAsset("HelloWorld").WithSource();
var newWorkingDir = testAsset.Path;

Directory.SetCurrentDirectory(newWorkingDir);
var projectPath = @".\HelloWorld.csproj";
// Should not throw on Windows
var runCommand = RunCommand.FromArgs(new[] { "--project", projectPath });
runCommand.ProjectFileFullPath.Should().NotBeNull();
}

[UnixOnlyFact]
public void RunParserAcceptsWindowsPathSeparatorsOnLinux()
{
var tam = new TestAssetsManager(output);
var testAsset = tam.CopyTestAsset("HelloWorld").WithSource();
var newWorkingDir = testAsset.Path;

Directory.SetCurrentDirectory(newWorkingDir);
var projectPath = @".\HelloWorld.csproj";
// Should not throw on Linux with backslash separators
var runCommand = RunCommand.FromArgs(new[] { "--project", projectPath });
runCommand.ProjectFileFullPath.Should().NotBeNull();
}
}
}
Loading