File-based apps: ensure shebang analyzer only applies to #:include#54397
Open
jjonescz wants to merge 2 commits into
Open
File-based apps: ensure shebang analyzer only applies to #:include#54397jjonescz wants to merge 2 commits into
#:include#54397jjonescz wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
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-addedCompileitems. - 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. |
Open
3 tasks
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.
To avoid breaking people that include
.csfiles via other means. See #53749 (comment).