Skip to content

Fix recognizing dotnet ./file.cs with special arguments #49909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jjonescz
Copy link
Member

Fixes #49892.

If dotnet ./Program.cs build is encountered, the command line is parsed as the BuildCommand, not RootCommand, hence I'm removing the check (which I don't think is necessary).

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Jul 23, 2025
@jjonescz jjonescz marked this pull request as ready for review July 23, 2025 12:09
@Copilot Copilot AI review requested due to automatic review settings July 23, 2025 12:09
Copy link
Contributor

@Copilot 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 an issue where dotnet ./file.cs with special arguments wasn't being recognized correctly. The problem occurred when additional arguments were passed (like dotnet ./Program.cs build) because the command line was incorrectly parsed as BuildCommand instead of RootCommand.

  • Removes the RootCommand check condition to allow C# file execution regardless of which command parser was used
  • Adds comprehensive test coverage for different file path formats and argument combinations

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Cli/dotnet/Program.cs Removes the RootCommand condition check to fix argument parsing issue
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Adds test cases for various file path formats and argument combinations
Comments suppressed due to low confidence (1)

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

  • [nitpick] This test case using Path.DirectorySeparatorChar may be redundant with the previous test on line 156 that uses "./Program.cs", since on Unix systems DirectorySeparatorChar is '/' making them identical. Consider testing a backslash scenario specifically or documenting the intent.
        new DotnetCommand(Log, $".{Path.DirectorySeparatorChar}Program.cs")

@jjonescz jjonescz requested a review from a team July 23, 2025 12:19
@jjonescz jjonescz requested review from RikkiGibson and MiYanni July 23, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-run-file Items related to the "dotnet run <file>" effort
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.NET 10 Shebang Issue: #!/usr/bin/dotnet intercepts script arguments as dotnet commands
4 participants