View compiler warnings without actually building the codebase?
Is there any way to view compiler warnings without actually building the codebase? As in something along the lines of "dotnet build --syntax-only" or "dotnet lint"?
I would prefer not to install a separate linter if I don't have too.
I want to write out the warnings from the compiler in a separate stage of my CI pipeline so my devs will actually pay attention to them lol. Thank you!
9 Replies
There is no separate "lint" stage of compilation
Got it, Thank you
.NET isn't like python/javascript or other scripting languages where you need to do some kind of separate analysis ahead of time. It's just "compile the program. Did that work? Cool"
If you want to make sure that devs pay attention to warnings (not errors), you can use
TreatWarningsAsErrors
to turn them into errors in your CI
That's what we generally do: leave warnings as warnings when you're just coding locally, to not make the inner loop unnecessarily long, but then enforce that there are no warnings in CI@Cheat-Code Sam It's also worth noting that warnings can also come from 3rd-party analyzers, which are run by Roslyn during compilation.
So even if you could find a separate linter that operates independent of the compiler, it would be missing those analyzer messages.
That makes sense, Thank you both of you for your answers. I have considered
TreatWarningsAsErrors
, but our codebases are so large it would be too much of a blocker.I'm assuming that's because you have a pre-existing number of warnings?
Yeah, a very large number of them
Most of them seem like simple fixes, like checking for null values
Gotcha. My suggestion in these types of cases is to blanket suppress all existing warnings to establish a baseline
Yes, it's a bit tedious to suppress them all
But once you do that, you can create backlog items to go and fix up the suppressions, and turn on TreatWarngsAsErrors to ensure you don't hemmorage even more
hmm I can definitely work with that.