Skip to content

File-based apps: extend "missing shebang" analyzer to #:ref directives#54553

Open
jjonescz wants to merge 2 commits into
dotnet:release/10.0.4xxfrom
jjonescz:53749-shebang-analyzer-refs
Open

File-based apps: extend "missing shebang" analyzer to #:ref directives#54553
jjonescz wants to merge 2 commits into
dotnet:release/10.0.4xxfrom
jjonescz:53749-shebang-analyzer-refs

Conversation

@jjonescz
Copy link
Copy Markdown
Member

@jjonescz jjonescz commented Jun 2, 2026

Resolves #53749.
Corresponding doc update: dotnet/docs#54120

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Jun 2, 2026
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

Extends the MissingShebangInFileBasedProgram analyzer (CA2266) so it also flags entry-point files that contain #:ref directives without a shebang line, mirroring the existing behavior for #:include. Tests across the run-file/convert suites are updated to add the shebang where appropriate, and analyzer unit tests are parameterized to cover the new directive. #:project and #:package are explicitly verified to NOT require a shebang.

Changes:

  • Renames IsIncludeDirective to IsShebangRequiringDirective and matches both include and ref via a small IsDirective helper.
  • Parameterizes analyzer unit tests with [Theory]/[InlineData] to cover include, ref, project, and package directive variants.
  • Adds shebangs to existing run-file and project-convert tests that use #:ref, plus a new MissingShebangWarning_RefDirective integration test; updates expected error line numbers (1 → 2).

Reviewed changes

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

Show a summary per file
File Description
src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.CSharp.NetAnalyzers/Microsoft.NetCore.Analyzers/Usage/CSharpMissingShebangInFileBasedProgram.cs Extends shebang-required detection to include #:ref in addition to #:include.
src/Microsoft.CodeAnalysis.NetAnalyzers/tests/.../Usage/MissingShebangInFileBasedProgramTests.cs Parameterizes analyzer tests; adds package/project no-diagnostic cases and ref warning/codefix cases.
test/dotnet.Tests/CommandTests/Run/RunFileTests_BuildOptions.cs Adds a new integration test asserting CA2266 fires for a #:ref entry point and disappears once a shebang is added.
test/dotnet.Tests/CommandTests/Run/RunFileTests_Directives.cs Adds shebangs to existing #:ref tests and updates expected directive error line number.
test/dotnet.Tests/CommandTests/Run/RunFileTests_General.cs Adds shebangs and bumps expected error line for #:ref tests.
test/dotnet.Tests/CommandTests/Run/RunFileTests_CscOnlyAndApi.cs Adds shebangs to entry-point sources that use #:ref.
test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs Adds shebangs to dotnet project convert test inputs that use #:ref.

@jjonescz
Copy link
Copy Markdown
Member Author

jjonescz commented Jun 8, 2026

@333fred @RikkiGibson for reviews, thanks

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.

2 participants