SonarQube for Visual Studio plugin version: 9.0.0.15771
Programming language you’re coding in: C#
Is connected mode used: yes
SonarQube Cloud, SonarQube Server, or SonarQube Community Build? (if one of the latter two, which version?): SonarQube Server v2025.5
And a thorough description of the problem / question:
We have observed
that now SonarQube findings in Visual Studio are now only marked as warnings and not anymore as errors, if you have TreatWarningsAsErrors enabled.
that SonarQube issues are not propagated to the compiler anymore, thus a pragma warning disable in the code will be removed by Visual Studio Code Cleanup extension to remove unnecessary code
So our question is now, how can we enable the TreatWarningsAsErrors feature again for SonarQube issues to break the build also in Visual Studio (shift left approach)?
And how can we use pragma warning disable again in the code itself, to make it clear, which suppressions are done in a file for later removal/fixes. I saw that the new version now is working with a settings.json, but we would like to have the suppression in the code itself.
At the moment we lost TreatWarningsAsErrors functionality with our recent 9.0 changes. Would you be more interested in having this back or having a separate customization for mapping from Sonar severities to VS’ Info/Warn/Error?
It’s possible to manage issue statuses in Connected Mode by changing SonarQube Server resolution status (via browser or via in-IDE context menu by right clicking on the issue). Does this functionality solve the problem for you?
I’ve checked and actually the pragmas still work for me. Can you provide a more specific example of how it’s not working?
I used #pragma warning disable S3776 with the rule csharpsquid:S3776
Both would be good I guess, but for our current code base and amount of projects, it would at least be nice to have the TreatWarningsAsErrors functionality back
@georgii.borovinskikh Same for me, having this feature back is kind of important for a “shift left” approach. Otherwise the feedback will be returned during build time in CI/CD which is kind of late already!
I will investigate the problem further. In the meantime, you can use the SonarQube Report view with Focus on New Code filter in order to see newly introduced issues: New code | Visual Studio | Sonar Documentation
Unfortunately, there’s no easy way to integrate this with VS build system in a way that preserves the old behavior 1-to-1. We will have an internal discussion in order to come up with a solution.
We’ve had a discussion and we agree with the concerns you raised.
We did an investigation into possible solutions, but none of them seemed straightforward enough for us to immediately jump into implementation. Unfortunately, we’ve not scheduled time to create a prototype yet.
A bit more details:
We can detect when the project uses TreatWarningsAsErrors and we can mark the issues as errors in the Error List/Sonar Report View, however there’s no way to contribute those errors to the MSBuild and fail the build natively. We could raise our own ‘notification’ to the developer if we detect that the build has started and there were errors detected during the last analysis. Would that be useful to you?
We can disable the ‘false-positive’ cleanup of #pragma warning disable via dotnet_remove_unnecessary_suppression_exclusions, but it will mean that those pragmas won’t be collected by the built-in cleanup anymore. We have not explored the possibility to have our own clean up mechanism, but it looks possible to do with Roslyn APIs. Would that be useful to you?
The first link I’ve sent you had a bug: we didn’t link the configuration file to the project, so it shouldn’t have worked at all. The second link is the one that should fix that and disable the cleanup for our rules.
The cleanup of no longer necessary pragmas was not implemented (yet).
We’ve released version 9.8.0.16314 to VS marketplace yesterday, can you run the update of the extension via VS and try again?
sorry I messed something up. I saw my visual studio auto updated the first version I installed to the latest one 9.8.0.16314 and while trying the second link and installing, something seems to went wrong and it looks like it went back to an older version.
I see sonar issues in the report view, but not as an error. Same for the “Error List” View. I see the issues there as “Message” for example for the S2094. At least as error or warning would be great, because we have the policy to have no warnings and errors, but mostly not look at the “Message” list (new language features are always in that list)