Sonar running on projects not surrounded by sonar build steps


We have a mono repo with many different projects within it. We’re using Azure DevOps with self-hosted build agents to build this. Most of the projects are C# .Net projects.
I’ve wrapped the build and test steps for the projects in “SonarCloudPrepare” and “SonarCloudAnalyze” steps. For the most part this seems to work well with each project getting its own analysis.
My question is though that there are a few projects/solutions within the monorepo that we do not want to run sonar over. Even though they are not surrounded by the Sonar steps it appears that when they are build they are running longer than before Sonar was introduced. I looked into the logs and i can see when they build that sonar is running on those projects too, even though they shouldnt be.
I see things like:
throught the logs of the projects NOT wrapped with SonarCloudPrepare and SonarCloudAnalyze steps.

Why is Sonar running over these when it shouldnt be? How can I stop it?

Another potential scenario we have is that sometimes i might want to run a build with sonar, then a build without it (using a build flag). Our self hosted agent during the day will often run incremental builds (i.e. it doesnt clear everything to save time), this also appears to be slowed by the fact sonar is running even though its not been requested to.


Hi @WillEllis and welcome to the community !

You have 2 possibilities to do so :

  • EIther delete the content of the .sonarqube folder at the end of the analysis
  • Or add the /p:SonarQubeTargetsImported=true msbuild parameter in the build after the one that has been “analyzed”

Please note that this is a workaround, we’re currently working on a proper fix to avoid to do that.

Sorry for the incovenience !


Hi Mickaël,

Thank you for your response.
I’ll try setting SonarQubeTargetsImported for projects we don’t want scanned when its running a build with Sonar.
Great to hear a fix is in the works, is there an issue somewhere I can follow to get notifications on it?

Thanks again

Yes, you can follow this GH issue : Improve uninstall of targets if multiple builds in the same pipeline · Issue #964 · SonarSource/sonar-scanner-msbuild · GitHub