Suppress Build Output When Running `dotnet run`
Asked Answered
U

3

10

Is it possible to suppress the build warnings which are output when dotnet run causes a build to occur, e.g. after a code change?

$ dotnet run --verbosity quiet

/../MyProgram.cs(6,21): warning CS8618: Non-nullable property
    'MyProperty' must contain a non-null value when exiting
    constructor. Consider declaring the property as nullable.

<My Program Output>

This is painful, as during development I will pipe my program output into another tool, and the build warning output breaks the parsing of that tool. I don't want to disable any particular warnings; I want to simply omit them from the output of dotnet run.

Unplumbed answered 27/10, 2022 at 12:16 Comment(0)
U
14
$ dotnet run --property WarningLevel=0
Unplumbed answered 28/10, 2022 at 11:33 Comment(0)
B
5

I have found that you need multiple switches for this to work more reliably:

dotnet build --nologo -v q --property WarningLevel=0 /clp:ErrorsOnly

where:

  • --nologo suppresses the header
  • -v q sets output verbosity to quiet
  • --property WarningLevel=0 is for MsBuild, and described well in other answers.
  • /clp:ErrorsOnly means ConsoleLoggerParameters

For reasons, I have not fully explored, dotnet run does not always respect these arguments, so I stitch these together with bash/pwsh:

dotnet build --nologo -v q --property WarningLevel=0 /clp:ErrorsOnly && dotnet run --no-build

Disclaimer: disabling warnings is a generally a bad idea

Blather answered 7/7, 2023 at 6:47 Comment(0)
D
0

This works for me:

dotnet run --verbosity error
dotnet yoor.dll --urls "http://+:portno" --verbosity error
Donegal answered 16/4 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.