Skip to content

File-based apps: ensure shebang analyzer only applies to #:include#54397

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

File-based apps: ensure shebang analyzer only applies to #:include#54397
jjonescz wants to merge 2 commits into
dotnet:release/10.0.4xxfrom
jjonescz:sprint-shebang-analyzer-break

Conversation

@jjonescz
Copy link
Copy Markdown
Member

To avoid breaking people that include .cs files via other means. See #53749 (comment).

@jjonescz jjonescz requested a review from Copilot May 21, 2026 13:00
@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label May 21, 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

This PR narrows the CA2266 (“missing shebang in file-based program”) behavior so it only triggers when additional C# source files are brought in via #:include, avoiding warnings for multi-file compilations caused by other MSBuild mechanisms (e.g., Directory.Build.props, project references, etc.).

Changes:

  • Emit compiler-visible item metadata in the generated virtual project so analyzers can distinguish #:include-added Compile items.
  • Update the CA2266 analyzer logic to only warn when a non-entrypoint syntax tree is marked as coming from #:include.
  • Adjust/extend CLI and analyzer unit tests to validate the new behavior and the generated project content.

Reviewed changes

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

Show a summary per file
File Description
test/dotnet.Tests/CommandTests/Run/RunFileTests_Directives.cs Updates API-based virtual project assertions to require the new compiler-visible metadata declaration.
test/dotnet.Tests/CommandTests/Run/RunFileTests_CscOnlyAndApi.cs Updates expected virtual project XML in CscOnly/API tests to include the compiler-visible metadata item.
test/dotnet.Tests/CommandTests/Run/RunFileTests_BuildOptions.cs Updates CA2266 expectations to ensure no warning from extra Compile items added via Directory.Build.props, while still warning for real #:include.
src/Microsoft.DotNet.ProjectTools/VirtualProjectBuilder.cs Adds <CompilerVisibleItemMetadata ...> so FileBasedProgramsFromIncludeDirective flows into analyzer config as build_metadata.Compile.*.
src/Microsoft.CodeAnalysis.NetAnalyzers/tests/.../MissingShebangInFileBasedProgramTests.cs Updates/extends analyzer tests to cover “include vs non-include extra file” behavior.
src/Microsoft.CodeAnalysis.NetAnalyzers/src/.../CSharpMissingShebangInFileBasedProgram.cs Changes CA2266 triggering condition to require presence of build_metadata.Compile.FileBasedProgramsFromIncludeDirective=true on at least one non-entrypoint tree.

@jjonescz jjonescz marked this pull request as ready for review May 22, 2026 13:56
@jjonescz jjonescz requested a review from a team as a code owner May 22, 2026 13:56
@jjonescz jjonescz requested a review from a team May 22, 2026 13:56
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