SonarQubePrepare@5 task with MSBuild in Azure DevOps pipelines analyses wrong folder

Hello, we are currently facing some problems when trying to perform a Sonar analysis in one of our ADO pipelines by using the SonarQubePrepare@5 task.

We are using Sonarqube Developer Edition Version 10.0 (build 68432) and the version of the Extension for Azure DevOps is 5.15.0

Below is the task that we are using:

task: SonarQubePrepare@5
    inputs:
    SonarQube: ‘nameOfSonarQubeServerEndpoint’
    scannerMode: ‘MSBuild’
    projectKey: ‘projectKeyName’
    projectName: ‘nameOfProject’
    extraProperties: |
          sonar.exclusions=`**`/`*`.js,`**`/`*`.tsx,`**`/`*`.ts,`**`/`*`.less,`**`/AssemblyInfo.cs
          sonar.projectBaseDir=$(Build.SourcesDirectory)\Folder1\Folder2
          sonar.cs.opencover.reportsPaths=“$(Build.SourcesDirectory)\CodeCoverage.xml”
          sonar.verbose=true

The problem is that we want to do an analysis only on the contents of Folder2 which is a module for our application (that’s why we provide that path using the sonar.projectBaseDir) but somehow no matter what we tried so far the analysis takes place also inside Folder1 which is the folder of the application itself.

Any ideas what we are not doing correctly ?

Thanks in advance.

1 Like

Hi,

I’ll start by saying that I find C# analysis a bit tricky. And I see two options here

  • override sonar.sources on the command line to point to just Folder2. I’m less optimistic about this one since a big part of what the SonarScanner for .NET does is define sonar.sources from the build environment.
  • drop sonar.exclusions and use sonar.inclusions=$(Build.SourcesDirectory)\Folder1\Folder2 I think this has a better chance of working since it builds on the sonar.sources definition crafted by the scanner. And when you do this, you can drop sonar.projectBaseDir as well.

 
HTH,
Ann

Hello, thanks for your response, I tried both solutions but those didn’t really work unfortunately… any other ideas maybe ?

Hi,

Would you care to share the outcome when you tried these two things?

 
Ann

Using both methods provided above it still seems that the analysis is done inside Folder1 instead of Folder2…

Hi,

That seems like a different problem than (emphasis mine):

So, is it that the contents of both Folder1 and Folder2 are analyzed? Or is the problem that only Folder1 is analyzed?

 
Ann

The contents of both folders seem to be analyzed…

Hi,

You’ll need to tune your analysis with inclusions or exclusions. The exact details will depend on your project structure. I’d advise you to play around with it until you get to settings that accomplish your goal. Do not use inclusions and exclusions together. That way lies madness.

 
Ann