Skip to content

Excluding generated code does not work #45810

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

Open
boppbo opened this issue Apr 15, 2025 · 2 comments
Open

Excluding generated code does not work #45810

boppbo opened this issue Apr 15, 2025 · 2 comments

Comments

@boppbo
Copy link

boppbo commented Apr 15, 2025

Type of issue

Missing information

Description

I refactored my code generator to emit .generated.cs instead of .g.cs trying to get rid of warnings. This did not change anything.
e.g. .generated.cs(11,30): Warning CS0169 : The field 'x' is never used.

As the runtime uses .g.cs it should be added or replace the .generated.cs entry in the list of valid patterns that are considered generated code (https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs)

Next I'm trying to use the GeneratedCodeAttribute as seen in the runtime file. This attribute isn't mentioned at all in docs.

Page URL

https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-options#exclude-generated-code

Content source URL

https://github.com/dotnet/docs/blob/main/docs/fundamentals/code-analysis/configuration-options.md

Document Version Independent Id

36879d50-dcc5-3376-9404-d60379024c0e

Platform Id

c266a76b-4885-d54c-7bd4-4aeae078a508

Article author

@gewarren

Metadata

  • ID: fa74a3f7-feef-0ec8-aebe-48bd106523dc
  • PlatformId: c266a76b-4885-d54c-7bd4-4aeae078a508
  • Service: dotnet-fundamentals

Related Issues

@gewarren
Copy link
Contributor

@boppbo The warning in your example, CS0169, doesn't come from code analysis - it comes from the C# compiler.

@boppbo
Copy link
Author

boppbo commented Apr 21, 2025

@boppbo The warning in your example, CS0169, doesn't come from code analysis - it comes from the C# compiler.

Yes, i learned that too and used #pragma directives to disable them. Thanks for trying to help.

Maybe it would be worth mentioning compiler warnings in this section as it was the article i found first and it would be nice to fall easier in the pit of success.

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

No branches or pull requests

2 participants