Skip to content

Skip shebang when checking transitive directive feature flag#53604

Open
jjonescz wants to merge 2 commits intodotnet:release/10.0.3xxfrom
jjonescz:sprint-shebang-optin
Open

Skip shebang when checking transitive directive feature flag#53604
jjonescz wants to merge 2 commits intodotnet:release/10.0.3xxfrom
jjonescz:sprint-shebang-optin

Conversation

@jjonescz
Copy link
Copy Markdown
Member

@jjonescz jjonescz commented Mar 26, 2026

Without this, #! in an #:included file requires the experimental opt-in which seems pointless since #! is ignored by the dotnet CLI.

@jjonescz jjonescz requested a review from a team March 26, 2026 17:51
@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Mar 26, 2026
Copilot AI review requested due to automatic review settings March 26, 2026 17:51
Copy link
Copy Markdown
Contributor

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

Updates file-based dotnet run directive feature-flag gating so that a shebang (#!) inside an included file doesn’t incorrectly require the transitive directives experimental flag, and adds a regression test to cover the scenario.

Changes:

  • Exclude CSharpDirective.Shebang from the transitive-directives feature-flag check when the directive originates from a non-entrypoint file.
  • Add a test validating that an included file containing only a shebang works with include-directive enabled (without enabling transitive directives).

Reviewed changes

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

File Description
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Adds regression coverage for shebang in an included file not requiring the transitive-directives flag.
src/Microsoft.DotNet.ProjectTools/VirtualProjectBuilder.cs Adjusts directive validation to skip shebang when deciding whether to require the transitive-directives feature flag.

""");

File.WriteAllText(Path.Join(testInstance.Path, "Util.cs"), $"""
#!/usr/bin/env dotnet
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like there is a risk that in the future, tooling will treat Util.cs as also being an entry point, due to presence of #!. Is it fine for an entry point to reference another entry point?

That said, I think I buy that the "is transitive directives feature flag enabled" check wouldn't be the place to enforce anything in particular about that anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it fine for an entry point to reference another entry point?

It can work. Even something as simple as file1.cs with top-level statements referencing file2.cs with a Main method - both work as standalone entry points too. Then there are the more complex cases of test frameworks that synthesize entry points - no file has an explicit entrypoint so they can reference each other but can also run separately.

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.

4 participants