Skip to content

Commit 99c8904

Browse files
authored
Fix recognizing dotnet ./file.cs with special arguments (#49909)
1 parent 17c6e86 commit 99c8904

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

src/Cli/dotnet/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ internal static int ProcessArgs(string[] args, TimeSpan startupTime)
286286
{
287287
// If we didn't match any built-in commands, and a C# file path is the first argument,
288288
// parse as `dotnet run --file file.cs ..rest_of_args` instead.
289-
if (parseResult.CommandResult.Command is RootCommand
290-
&& parseResult.GetValue(Parser.DotnetSubCommand) is { } unmatchedCommandOrFile
289+
if (parseResult.GetValue(Parser.DotnetSubCommand) is { } unmatchedCommandOrFile
291290
&& VirtualProjectBuildingCommand.IsValidEntryPointPath(unmatchedCommandOrFile))
292291
{
293292
List<string> otherTokens = new(parseResult.Tokens.Count - 1);

test/dotnet.Tests/CommandTests/New/DotnetSlnPostActionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void AddProjectToSolutionPostActionFindSolutionFileAtOutputPath()
2929
Assert.Equal(solutionFileFullPath, solutionFiles[0]);
3030
}
3131

32-
[Fact(DisplayName = nameof(AddProjectToSolutionPostActionFindSlnxFileAtOutputPath))]
32+
[PlatformSpecificFact(TestPlatforms.Any & ~TestPlatforms.Linux)] // https://github.com/dotnet/sdk/issues/49923
3333
public void AddProjectToSolutionPostActionFindSlnxFileAtOutputPath()
3434
{
3535
string targetBasePath = _engineEnvironmentSettings.GetTempVirtualizedPath();

test/dotnet.Tests/CommandTests/Run/RunFileTests.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,34 @@ Hello from Program
142142
{s_program}
143143
""");
144144

145+
string expectedOutput = """
146+
Hello from Program
147+
Release config
148+
""";
149+
145150
new DotnetCommand(Log, "Program.cs")
146151
.WithWorkingDirectory(testInstance.Path)
147152
.Execute()
148153
.Should().Pass()
149-
.And.HaveStdOut("""
150-
Hello from Program
151-
Release config
152-
""");
154+
.And.HaveStdOut(expectedOutput);
155+
156+
new DotnetCommand(Log, "./Program.cs")
157+
.WithWorkingDirectory(testInstance.Path)
158+
.Execute()
159+
.Should().Pass()
160+
.And.HaveStdOut(expectedOutput);
161+
162+
new DotnetCommand(Log, $".{Path.DirectorySeparatorChar}Program.cs")
163+
.WithWorkingDirectory(testInstance.Path)
164+
.Execute()
165+
.Should().Pass()
166+
.And.HaveStdOut(expectedOutput);
167+
168+
new DotnetCommand(Log, Path.Join(testInstance.Path, "Program.cs"))
169+
.WithWorkingDirectory(testInstance.Path)
170+
.Execute()
171+
.Should().Pass()
172+
.And.HaveStdOut(expectedOutput);
153173

154174
new DotnetCommand(Log, "Program.cs", "-c", "Debug")
155175
.WithWorkingDirectory(testInstance.Path)
@@ -168,6 +188,16 @@ Hello from Program
168188
Hello from Program
169189
Release config
170190
""");
191+
192+
new DotnetCommand(Log, "Program.cs", "build")
193+
.WithWorkingDirectory(testInstance.Path)
194+
.Execute()
195+
.Should().Pass()
196+
.And.HaveStdOut("""
197+
echo args:build
198+
Hello from Program
199+
Release config
200+
""");
171201
}
172202

173203
/// <summary>

0 commit comments

Comments
 (0)