Provide custom file header option for compatibility with BannedApiAnalyzer
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.5k
- Forks
- 124
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
I have a code-base I'm slowly moving away from public PInvoke methods (which was a bad decision by me), and I've started to create wrappers around the stuff I need.
To enforce this, I've added the BannedApiAnalyzer and marked the PInvoke methods I've already moved to matching wrappers.
However, the BannedApiAnalyzer sees the banned APIs used in the generated PInvoke classes and when using <WarningsAsErrors> with RS0030 it will error out the build.
Describe the solution you'd like
Provide an option that allows me to specifiy additional analyzer symbols to disable, either as a list, or with freeform custom file header field.
Describe alternatives you've considered
Either not using WarningsAsErrors for but rely on Warnings being emitted, and scrolling through the log.
I had the idea of using Doesn't work.<WarningsAsErrors Condition="'$(BuildingInsideVisualStudio)'=='True'">RS0030;$(WarningsAsErrors)</WarningsAsErrors>, but I've not verified this yet.
Additional context
Using WarningsAsErrors won't work, but somehow this does indeed work:
.editorconfig
[*.{cs,vb}]
dotnet_diagnostic.RS0030.severity = error
[*/Microsoft.Windows.CsWin32.SourceGenerator/*.cs]
generated_code = true
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository files or tests are named. Start by locating the generated P/Invoke file-header logic and existing analyzer-related tests, then reproduce the RS0030 failure with WarningsAsErrors and the provided .editorconfig pattern. Done means a configurable header or analyzer-symbol option prevents the generated APIs from failing the build while preserving diagnostics elsewhere.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100