Exclude from Build-Analysis (C# and VB.net)

Hi there

We are doing a SonarQube-Code-Analysis in an Azure Pipeline. We are using SonarQube 8.5.1. The analysis works fine and I get a proper result. But the pipeline takes forever to finish.
Buildtime without SonarQube: 5-10 mins
Buildtime with SonarQube: 25-30 mins

The task that takes the longest is the actual build with msbuild (MSBuild@1). The analysis task (SonarQubeAnalyze@4) takes only 2 mins.

I have several exclusions defined in the SonarQubePrepare@4 step with sonar.exclusions. But these exclusions don’t seem to work during the build.

I as well added folloing project config in a Directory.Build.props file

<project>
  <ItemGroup>
    <SonarQubeSetting Include="sonar.coverage.exclusions">
        <Value>Source/UiWebDefinitions/**/*,Source/UiWeb/**/*,**/*.xml,packages/**/*,Test/**/*,docs/**/*,**/obj/**/*,Source/**/*Form.*,Source/**/*.designer.*,Source/**/*.resx,**/*.dll,**/*.exe</Value>
    </SonarQubeSetting>
 </ItemGroup>
</Project>

(Sorry about the formatting but I could

… but without any improvements.

My question is: How can I properly exclude files from the build-analysis?

Thanks for your help.
Just let me know if you need additional information.

mitti2000

Hi @mitti2000,

Short answer is: You can’t.

Our rules runs on all files due to the way we integrate with Roslyn. You can only define exclusions to ignore the issues found. Another thing is that the coverage exclusion you’ve set only applies to coverage results, not on issues found.

You can add /p:reportanalyzer=true /v:d MSBuild parameters to your build step to figure out what rules take the most time and share the result with us. The output should look like this:

otal analyzer execution time: 893.913 seconds.
NOTE: Elapsed time may be less than analyzer execution time because analyzers can run concurrently.
Time (s) % Analyzer
893.913 100 SonarAnalyzer.CSharp, Version=7.13.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244
448.313 50 SonarAnalyzer.Rules.CSharp.RULE_X
445.228 49 SonarAnalyzer.Rules.CSharp.RULE_Y