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

Error adding PublicApiAnalyzers to Razor Class Library #7553

Open
AndersenBell opened this issue Jan 31, 2025 · 0 comments
Open

Error adding PublicApiAnalyzers to Razor Class Library #7553

AndersenBell opened this issue Jan 31, 2025 · 0 comments

Comments

@AndersenBell
Copy link

Analyzer

Diagnostic ID: RS0016: Symbol 'BuildRenderTree' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.PublicApiAnalyzers

Version: 3.3.4

Describe the bug

Razor libraries are not handled well when turning on the PublicApiAnalyzers rules.

Warnings get created on generated code and it is impossible to turn them off without disabling it for the entire project.

Adding an entry for [*.g.cs] does not work.

For example:

C:\repo\RazorClassLibrary1\obj\Debug\net8.0\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Component1_razor.g.cs(25,33,25,48): warning RS0016: Symbol 'BuildRenderTree' is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Component1_razor.g.cs is generated, and BuildRenderTree is on the base class.

This would be workable if I could solve it by adding a line to the PublicAPI.Shipped.txt but this does not work:

virtual Component1.BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder! builder) -> void

Steps To Reproduce

  1. Create a new Razor class library
  2. Add the PublicApiAnalyzers package
  3. build
  4. look at warnings
  5. attempt to resolve any of them

Expected behavior

Ideally, it would handle razor inheritance correctly, or it would resolve if I manually added a line to PublicAPI.Shipped.txt

Actual behavior

nothing works

Additional context

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

1 participant