Given a .Net C# project I want to check if the build contains warnings. When running the command
dotnet build -consoleloggerparameters:"Summary;Verbosity=normal" -m -p:"WarnLevel=5;EnforceCodeStyleInBuild=true" -t:"clean,build"
I get the expected output
Build succeeded.
2 Warning(s)
0 Error(s)
But the exit code is 0, so how do I know if that build contains warnings?
I created a shell script to play around
#!/bin/bash
dotnet build -consoleloggerparameters:"Summary;Verbosity=normal" -m -p:"WarnLevel=5;EnforceCodeStyleInBuild=true" -t:"clean,build"
if [ $? -eq 0 ]
then
echo ">>> Success"
else
echo ">>> Contains warnings or errors"
fi
read
but how can I extend the script to check for a successful build with warnings? The configured CI pipelines should pass but I want to mark them as unstable if warnings occured.
I would like to avoid Regex magic if possible.
Edit:
I don't want to add the flag -warnaserror because then CI pipelines will fail and you won't get to know if build errors occured or the code style is just bad.