✅ Can’t disable warnings in generated code
My warnings as errors pipeline is failing because of generated code ending with .g.cs which doesn’t have xml comments.
I added the following to the editorconfig at the root of my solution:
But the warnings keep appearing. Is this not a valid selector for editorconfig?
19 Replies
I believe
.g.cs
files already do not report warnings, although that warning might override it (?)Yeah I would have thought it was a standard exclusion, having read .designer is exempt too
I think that generated code only disables some warnings, not all of them
Unfortunately it’s not my generator so I can’t add the comments or an auto generated comment
But if I specifically suppress cs1591 that doesn’t work either
dotnet_diagnostic.CS1591.severity = none
Also yeah
.g.cs
is automatically registered
Pretty sure that editorconfig only lets you change code style, not disable warnings
You'd need NoWarn in csproj for thatYou can suppress stylecop and ca warnings
But I guess those are analysers and this is the compiler?
Yeah but those aren't "real" warnings
Yeah I can’t suppress it in an actual file
That sucks
Pretty sure NoWarn could only disable it project wide which I absolutely don’t want to do
Thanks for the help guess I’m not using the generator
Why not exclude that warning from warnaserrror?
I do want it to warn as error in user code
Mind you there’s a stylecop warning that’s basically identical
Use a
.globalconfig
instead. Those apply to everything, including things without paths
Then turn it back on in your .editorconfig
for your user codeThat is a really good idea if it works
I'll have to try that tomorrow, if it works I will be very grateful
don't you also need a special comment at the top of the file to have it recognize as generated?
or is that just an option in addition to
.g.cs
?There's several ways to have a file be recognized as generated
.g being one
I think I usually do both .g and the comment
comment being another
yea
It has <auto-generated /> but the compiler does not care
Also @333fred the globalconfig approach worked, thank you so much ☺️
Yw. Feel free to $close the thread if there's nothing else
Use the /close command to mark a forum thread as answered