Skip to content

[release/10.0.3xx] File-based apps: ensure shebang analyzer only applies to #:include - #54525

Merged
jjonescz merged 2 commits into
dotnet:release/10.0.3xxfrom
jjonescz:sprint-shebang-analyzer-break-10.0.3xx
Jun 1, 2026
Merged

jjonescz merged 2 commits into
dotnet:release/10.0.3xxfrom
jjonescz:sprint-shebang-analyzer-break-10.0.3xx

Conversation

@jjonescz

@jjonescz jjonescz commented Jun 1, 2026 •

Copy link
Copy Markdown
Member

Backport of #54397.

Description

Ensures that a new analyzer (CA2266) introduced in 10.0.300 only applies to new scenarios to avoid a breaking change. This analyzer was always about #:include directives (a feature of file-based apps that was also introduced in 10.0.300) but it was implemented in such a way that it also applied to file-based apps that somehow included .cs files in other ways than via #:include - for example via <Compile> items imported through custom SDKs or msbuild targets from nuget packages.

Customer impact

Reported by a customer on GitHub - #53749 (comment).

Regression

I guess yes since it can break people's builds.

Risk

Low. Scoped change. Unit test coverage.

@jjonescz
jjonescz marked this pull request as ready for review June 1, 2026 08:47
@jjonescz
jjonescz requested a review from a team as a code owner June 1, 2026 08:47
Copilot AI review requested due to automatic review settings June 1, 2026 08:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This backport updates the CA2266 “missing shebang” analyzer behavior for file-based apps so it only triggers when the entry-point file uses #:include, avoiding warnings for multi-file compilations created via other mechanisms (e.g., extra Compile items from MSBuild props).

Changes:

  • Update CSharpMissingShebangInFileBasedProgram to require a #:include directive (and no shebang) before reporting CA2266.
  • Expand/adjust CLI integration tests to cover Directory.Build.props extra Compile items vs real #:include, including non-.cs includes.
  • Update analyzer unit tests to align with the new triggering condition and reduce duplicated solution-transform code.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Adjusts and adds file-based dotnet run tests to ensure CA2266 only fires for #:include (including non-.cs includes).
src/Microsoft.CodeAnalysis.NetAnalyzers/tests/Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/Microsoft.NetCore.Analyzers/Usage/MissingShebangInFileBasedProgramTests.cs Updates analyzer unit tests to require #:include for CA2266 and adds a “multiple files without include” coverage case.
src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.CSharp.NetAnalyzers/Microsoft.NetCore.Analyzers/Usage/CSharpMissingShebangInFileBasedProgram.cs Changes analyzer logic to look for an #:include directive in leading trivia before reporting CA2266.
src/Cli/dotnet/Commands/Run/CSharpCompilerCommand.Generated.cs Updates the generated template header comment (but currently references a test name that doesn’t exist in this branch).

Comment thread src/Cli/dotnet/Commands/Run/CSharpCompilerCommand.Generated.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@jjonescz

jjonescz commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

@RikkiGibson @333fred for a sign off on a backport, thanks

@jjonescz jjonescz added Servicing-approved Area-run-file Items related to the "dotnet run <file>" effort labels Jun 1, 2026
@jjonescz
jjonescz merged commit 7554d51 into dotnet:release/10.0.3xx Jun 1, 2026
30 checks passed
@jjonescz
jjonescz deleted the sprint-shebang-analyzer-break-10.0.3xx branch June 1, 2026 17:22
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 12, 2026
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 Servicing-approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants