From ee0b514cf92f7702ae58c2120fe6f7a57462b6f4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Sep 2025 18:13:45 +0000 Subject: [PATCH 1/2] Initial plan From 8eb2ee51df2c27134efb364ab5dae6b390be506f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Sep 2025 18:37:44 +0000 Subject: [PATCH 2/2] Fix Windows path separator handling in dotnet run on Linux Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com> --- src/Cli/dotnet/Commands/Run/RunCommand.cs | 7 +++++ .../CommandTests/Run/RunParserTests.cs | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Cli/dotnet/Commands/Run/RunCommand.cs b/src/Cli/dotnet/Commands/Run/RunCommand.cs index 8d88d22d6d98..bd2442167fe9 100644 --- a/src/Cli/dotnet/Commands/Run/RunCommand.cs +++ b/src/Cli/dotnet/Commands/Run/RunCommand.cs @@ -529,6 +529,13 @@ internal static void ThrowUnableToRunError(ProjectInstance project) projectFileOrDirectoryPath = Directory.GetCurrentDirectory(); } + // 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 != '\\') + { + projectFileOrDirectoryPath = projectFileOrDirectoryPath.Replace('\\', '/'); + } + string? projectFilePath = Directory.Exists(projectFileOrDirectoryPath) ? TryFindSingleProjectInDirectory(projectFileOrDirectoryPath) : projectFileOrDirectoryPath; diff --git a/test/dotnet.Tests/CommandTests/Run/RunParserTests.cs b/test/dotnet.Tests/CommandTests/Run/RunParserTests.cs index 3c2897bbe34e..b47f27a41e5a 100644 --- a/test/dotnet.Tests/CommandTests/Run/RunParserTests.cs +++ b/test/dotnet.Tests/CommandTests/Run/RunParserTests.cs @@ -27,5 +27,35 @@ 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(); + } } }