Sonarqube for IDE [Visual Studio] issues/questions

  • Operating system: Windows 11 Enterprise 23H2
  • Visual Studio version: 2022 Patch 17.14.21
  • 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.

Greetings

Markus Kramer

2 Likes

Hi @Lutti1988

  1. 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?
  2. 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

Sorry I just realized I misread the second question. Can you link the extension you’re referring to?

Hello,

  1. 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

  2. We are using the built-in CodeCleanup on Save extension: https://visualstudiomagazine.com/articles/2022/01/11/code-cleanup-on-save.aspx
    there I did the following configuration:

Greetings

Markus Kramer

@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.

2 Likes