0
votes

I have an MSBuild project which is analyzed using Sonar Scanner for MSBuild. I have passed the following sonar.exclusion properties as part of my pipeline script to exclude a folder from the analysis. But all my exclusion combinations fail to actually exclude the files.

/d:sonar.exclusions=\"IxMilia.Dxf/**,IxMilia.Dxf/*,**/IxMilia.Dxf,**/IxMilia.Dxf/**,**/IxMilia.Dxf/**/*,**/IxMilia.Dxf/*.cs,IxMilia.Dxf/*.cs\"

I tried passing the same from the Sonar UI under Analysis Scope, which did not help either.

The sonar output looks like this:

INFO: -------------  Scan IxMilia.Dxf
INFO: Initializer GenericCoverageSensor
INFO: Initializer GenericCoverageSensor (done) | time=0ms
INFO: Base dir: C:\Program Files (x86)\Jenkins\jobs\MCDC_Dev\workspace\IxMilia.Dxf

INFO: Source encoding: UTF-8, default locale: en_IN
INFO: Index files
INFO: Excluded sources: 
INFO:   IxMilia.Dxf/**
INFO:   IxMilia.Dxf/*
INFO:   **/IxMilia.Dxf
INFO:   **/IxMilia.Dxf/**
INFO:   **/IxMilia.Dxf/**/*
INFO:   **/IxMilia.Dxf/*.cs
INFO:   IxMilia.Dxf/*.cs
INFO: Analyzer working directory contains 5 .pb file(s)
INFO: 200 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns

As you can see from the output the logs, I want to exclude the folder present at the root of the workspace C:\Program Files (x86)\Jenkins\jobs\MCDC_Dev\workspace\IxMilia.Dxf

The IxMilia.Dxf folder contains .cs files which are referred while building the cs project.

Any help on this is appreciated.

1
look at one of the files you'd like to exclude in the SonarQube UI. At the top, you should see the path to the file as SonarQube understand it. Verify that it should match one of your patterns. - G. Ann - SonarSource Team
Thanks for ur reply @G.Ann-SonarSourceTeam .I looked into SonarQube UI and this is how it looks mc-design-converter --> IxMilia.Dxf . Now mc-design-converter is the name of the project in sonar. Changing the exclusion pattern to this does not help either. INFO: Excluded sources: INFO: mc-design-converter/IxMilia.Dxf/** INFO: Analyzer working directory contains 5 .pb file(s) INFO: 200 files indexed INFO: 0 files ignored because of inclusion/exclusion patterns - amal jayaraj

1 Answers

1
votes

I have found a solution for this. The Sonar.exclusions parameter does not directly work for Sonar Scanner for MSBuild unlike the general Sonar Scanner. For MSBuild projects, we need to add the exclusion in the .csproj which we want to exclude. Adding the below code to the .csproj file will result in the exclusion of files according to the configured pattern.

<Target Name="BeforeBuild">
<ItemGroup>
      <SonarQubeSetting Include="sonar.exclusions">
          <Value>/**</Value>
      </SonarQubeSetting>
</ItemGroup>
</Target>
</Project>

In the above-mentioned code, all files under the project folder get excluded since /** is passed as the value. You can refer this thread for more details: http://www.it1me.com/it-answers?id=35656157&ttl=SonarQube+with+C%23+plugin+with+MSBuild+Runner+does+not+take+exclusions