Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silence all warnings in dotnet cli output

I'm trying to silence all warnings in the output of the following command

dotnet watch run

I enabled a set of analyzers and there are a bit too many warnings right now. What makes this worse is that for some reason if I execute this command inside a docker container, for some weird reason I don't understand the errors are listed first and the warnings after them. So it's extremely annoying to find out what the error is when there are warnings. Especially as docker-compose is removing the color from the output, so the errors are hard to distinguish from warnings. I realize this setup is far from ideal for .NET, but it will take some time to fix this.

The warnings are shown in VS Code, they are really just noise in this command, especially as they are shown on every reload. In general I would prefer to handle the warnings only in VS Code, they are redundant in the output of this command.

I could not find any way to remove these warnings from the dotnet cli commands and keep them in VS code. Is there a way to disable all warnings in the dotnet cli commands, without affecting the display of these warnings inside VS Code?

like image 240
Fabian Avatar asked Oct 15 '25 21:10

Fabian


1 Answers

linux solution

You can use grep command with --line-buffered and --invert-match flags, like this:

dotnet watch run | grep --invert-match WARNING --line-buffered
  • --invert-match WARNING will match every line that doesn't have WARNINIG in it
  • --line-buffered enables real time output.

windows solution

On windows with powershell you can use Select-String powershell cmdlet instead of grep:

dotnet watch run | Select-String -Pattern WARNINIG -NotMatch
  • -Pattern - regex pattern to match
  • -NotMatch - inverses matching, so lines that don't have Pattern will be matched

On windows in regular cmd you can use findstr command:

dotnet watch run | findstr /V warning
  • warning - what is being matched
  • /V - inverses matching
like image 69
Monsieur Merso Avatar answered Oct 18 '25 11:10

Monsieur Merso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!