Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude single files when using MSBuild Scanner

We are using the SonarQube Scanner for MSBuild (1.1.0.0) and have a solution containing multiple projects.

There is a SonarQube.Analysis.xml in the solution root folder which we supply to the scanners cli.

<SonarQubeAnalysisProperties  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">
    <Property Name="sonar.cs.opencover.reportsPaths">output/nunit-coverage.xml</Property>
    <Property Name="sonar.cs.nunit.reportsPaths">output/nunit-result.xml</Property>

    <Property Name="sonar.exclusions">Project1/Migrations/*</Property>
    <Property Name="sonar.coverage.exclusions">Project1/Migrations/*</Property>
</SonarQubeAnalysisProperties>

Now the problem is: Project1/Migrations/* seems not to get excluded because the Base dir is set to .../Project1 during the scan. The same happens for all other projects in the solution. The result is that .../Project1/Project1/Migrations/* is an unknown path.

So what is the recommended way to exclude a whole directory from coverage and sourcecode analytics when using MSBuild Scanner?

like image 358
philipooo Avatar asked Oct 17 '22 18:10

philipooo


1 Answers

Try to put the exclusions in the project file (.csproj) itself, something like:

<ItemGroup>
     <SonarQubeSetting Include="sonar.exclusions">
          <Value>**/Migrations/*</Value>
     </SonarQubeSetting>
</ItemGroup>

See Appendix 2: Configuring the SonarQube Scanner for MSBuild.

like image 133
Danko Durbić Avatar answered Oct 21 '22 03:10

Danko Durbić