Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow BannedApiAnalyzer to ignore GeneratedCodeAttribute #7532

Open
dnv-kimbell opened this issue Jan 15, 2025 · 2 comments
Open

Allow BannedApiAnalyzer to ignore GeneratedCodeAttribute #7532

dnv-kimbell opened this issue Jan 15, 2025 · 2 comments

Comments

@dnv-kimbell
Copy link

Currently the BannedApiAnalyzer processes generated code that the developer has little control over.
It would be very helpful if the analyzer could optionally ignore code marked with GeneratedCodeAttribute.

The analysis framework seems to have some functionality in place to ignore generated code.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.diagnostics.generatedcodeanalysisflags?view=roslyn-dotnet-4.9.0

@bradwilson
Copy link

context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);

@bradwilson
Copy link

An alternative here would be to ignore entry points. The code that's being triggered is a non-async Main method using .GetAwaiter().GetResult(), which is exactly what the compiler does when translating an async Main to generate the required non-async Main.

We are also willing to add GeneratedCodeAttribute to the class in question if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants