[release/10.0.3xx] File-based apps: ensure shebang analyzer only applies to #:include - #54525
Merged
jjonescz merged 2 commits intoJun 1, 2026
Conversation
…ies to `#:include`
Contributor
There was a problem hiding this comment.
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
CSharpMissingShebangInFileBasedProgramto require a#:includedirective (and no shebang) before reporting CA2266. - Expand/adjust CLI integration tests to cover
Directory.Build.propsextraCompileitems vs real#:include, including non-.csincludes. - 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). |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Member
Author
|
@RikkiGibson @333fred for a sign off on a backport, thanks |
333fred
approved these changes
Jun 1, 2026
This was referenced Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
#:includedirectives (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.csfiles 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.