SonarScanner v4.11.0
Hi all!
I’ve written about this issue before, but I made various incorrect assumptions, and didn’t understand exactly what caused the issue - but please still bear with me as I am new to SonarQube!
So we basically have an Azure DevOps Build pipeline setup (it doesn’t make a difference that this is in an Azure DevOps pipeline, the same thing would happen if I ran all of this manually on my PC) - this pipeline simply does a ‘Prepare Analysis Configuration’ step (this is a step designed by SonarQube for integration with the pipeline), then it builds the solution, runs the unit tests, and then finalizes the code analysis.
This configuration can be seen below:
The analysis is set to integrate with MSBuild.
The analysis itself works as intended - we don’t have any issues there. The issue is that there’s 1 edge case we’ve found so far where it doesn’t work as intended.
If we run this build with an unused variable reference, it should fail the build, as this is how we have it configured - but for some reason, the build passes successfully, and instead reports the issue as a code smell.
If we run this same version of the code with the same unused variable reference, but without the SonarQube analysis steps before and after the build, the build fails as we would expect with (approximately) the following error:
Source\SomeCodeProbably\NormalViewModel.cs(230,22): Error CS0414: The field ‘NormalViewModel.disposed’ is assigned but its value is never used
Does anyone have any idea why SonarQube does this, and how we can make it work as expected?
With other issues that SonarQube picks up as code smells, if we run the non-SonarQube build on that version of the code, it passes successfully - as we would expect for those code-smells, there just seems to be this one point of overlap between SonarQube and our build rules where SonarQube seems to catch the build error and instead report it as a code smell!
Help is appreciated, and apologies if I’ve missed any information, I’ll happily add more information!