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
333fred
333fred4mo ago
There is no separate "lint" stage of compilation
Cheat-Code Sam
Cheat-Code SamOP4mo ago
Got it, Thank you
333fred
333fred4mo ago
.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
jcotton42
jcotton424mo ago
@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.
Cheat-Code Sam
Cheat-Code SamOP4mo ago
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.
333fred
333fred4mo ago
I'm assuming that's because you have a pre-existing number of warnings?
Cheat-Code Sam
Cheat-Code SamOP4mo ago
Yeah, a very large number of them Most of them seem like simple fixes, like checking for null values
333fred
333fred4mo ago
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
Cheat-Code Sam
Cheat-Code SamOP4mo ago
hmm I can definitely work with that.
Want results from more Discord servers?
Add your server