diff --git a/src/Cli/dotnet/Program.cs b/src/Cli/dotnet/Program.cs index 71feefd8e7f9..077d46aa615a 100644 --- a/src/Cli/dotnet/Program.cs +++ b/src/Cli/dotnet/Program.cs @@ -306,19 +306,19 @@ internal static int ProcessArgs(string[] args, TimeSpan startupTime) { // If we didn't match any built-in commands, and a C# file path is the first argument, // parse as `dotnet run --file file.cs ..rest_of_args` instead. - if (parseResult.GetValue(Parser.DotnetSubCommand) is { } unmatchedCommandOrFile - && VirtualProjectBuildingCommand.IsValidEntryPointPath(unmatchedCommandOrFile)) + if (parseResult.GetResult(Parser.DotnetSubCommand) is { Tokens: [{ Type: TokenType.Argument, Value: { } } unmatchedCommandOrFile] } + && VirtualProjectBuildingCommand.IsValidEntryPointPath(unmatchedCommandOrFile.Value)) { List otherTokens = new(parseResult.Tokens.Count - 1); foreach (var token in parseResult.Tokens) { - if (token.Type != TokenType.Argument || token.Value != unmatchedCommandOrFile) + if (token != unmatchedCommandOrFile) { otherTokens.Add(token.Value); } } - parseResult = Parser.Parse(["run", "--file", unmatchedCommandOrFile, .. otherTokens]); + parseResult = Parser.Parse(["run", "--file", unmatchedCommandOrFile.Value, .. otherTokens]); InvokeBuiltInCommand(parseResult, out var exitCode); return exitCode; diff --git a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs index 72c7f082d9b4..06d59a59bed2 100644 --- a/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs +++ b/test/dotnet.Tests/CommandTests/Run/RunFileTests.cs @@ -264,6 +264,17 @@ Release config Hello from Program Release config """); + + // https://github.com/dotnet/sdk/issues/52108 + new DotnetCommand(Log, "Program.cs", "Program.cs") + .WithWorkingDirectory(testInstance.Path) + .Execute() + .Should().Pass() + .And.HaveStdOut(""" + echo args:Program.cs + Hello from Program + Release config + """); } ///