✅ 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:
[*.g.cs]
generated_code = true
[*.g.cs]
generated_code = true
But the warnings keep appearing. Is this not a valid selector for editorconfig?
19 Replies
Thinker
Thinker13mo ago
I believe .g.cs files already do not report warnings, although that warning might override it (?)
dreadfullydistinct
dreadfullydistinctOP13mo ago
Yeah I would have thought it was a standard exclusion, having read .designer is exempt too
Petris
Petris13mo ago
I think that generated code only disables some warnings, not all of them
dreadfullydistinct
dreadfullydistinctOP13mo ago
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
Petris
Petris13mo ago
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 that
dreadfullydistinct
dreadfullydistinctOP13mo ago
You can suppress stylecop and ca warnings But I guess those are analysers and this is the compiler?
Petris
Petris13mo ago
Yeah but those aren't "real" warnings
dreadfullydistinct
dreadfullydistinctOP13mo ago
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
Petris
Petris13mo ago
Why not exclude that warning from warnaserrror?
dreadfullydistinct
dreadfullydistinctOP13mo ago
I do want it to warn as error in user code Mind you there’s a stylecop warning that’s basically identical
333fred
333fred13mo ago
Use a .globalconfig instead. Those apply to everything, including things without paths Then turn it back on in your .editorconfig for your user code
dreadfullydistinct
dreadfullydistinctOP13mo ago
That is a really good idea if it works I'll have to try that tomorrow, if it works I will be very grateful
jcotton42
jcotton4213mo ago
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?
Thinker
Thinker13mo ago
There's several ways to have a file be recognized as generated .g being one
jcotton42
jcotton4213mo ago
I think I usually do both .g and the comment
Thinker
Thinker13mo ago
comment being another yea
dreadfullydistinct
dreadfullydistinctOP13mo ago
It has <auto-generated /> but the compiler does not care Also @333fred the globalconfig approach worked, thank you so much ☺️
333fred
333fred13mo ago
Yw. Feel free to $close the thread if there's nothing else
MODiX
MODiX13mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server