C# classes no more in code analysis scope

Hi,
in my dotnet project I have a problem with the code analysis.
By running the analysis with the old SonarScanner for MSBuild 4.5, all C# source code are analyzed correctly and reported in Sonarqube (2 subfolder, 624 classes)
By running the analysis with the new SonarScanner for MSBuild 4.6.2, only a subset of the C# source code are analyzed, (15 classes)
On the Code view of the project, I see that only 1 subfolder is reporting Lines of Code (the 15 classes),
the big part of the code present on the other subfolder is completely not present

The build process is done with a CICD pipeline with Jenkins, the code is not changed, we just update the SonarScanner for MSBuild

  • Developer Edition
  • Version 7.9.1 (build 27448)
  • SonarScanner for MSBuild 4.6.2 (4.5)

thanks for your help
Bye Stefano

Hi @sbianda.

Out of interest: why did you upgrade to v4.6.2 rather than to the latest version of the scanner?

The only change I can think of between v4.5 and v4.6.2 that could have resulted in fewer projects being analyzed is S4MSB-651, which would result in XUnit projects being correctly identified as test projects, and not analysed. However, it sounds like you have too much missing code for that to account for all of it.

Some questions:

  • have you tried reverting back to v4.5 of the scanner?
  • ave there been any changes to the Jenkins pipeline?
  • are there any warnings in the MSBuild or scanner end steps?
  • how many projects are not being analyzed now, and what types of project are they? (e.g. class libraries, test projects etc)

Hi Duncan,
we update the server last year in December to 7.9.1 and on that moment the v4.6.2 was the last updated version of the scanner.
Yes, I did the tests yesterday with 4.6.2 and 4.5, the reported value are the result of this 2 tests.
I read the issue you mentioned, I have the other effect, a non test project seems to recognize as a test project and not analyzed.
is it possible to set

<SonarQubeTestProject>false</SonarQubeTestProject>

I have remarked that on the missing analyzed folder, there are few test classes; could be this the problem?

On end step I found some WARN like

WARN: File 'C:\Users\svcpjenkins\AppData\Local\Temp\.NETFramework,Version=v4.7.1.AssemblyAttributes.cs' referenced by the protobuf 'TokenTypeInfo' does not exist in the analysis context

There are only few projects that have this effect, a large number of projects are working correctly.
I think there is something on that project that run on the problem
Bye Stefano

did you manage to find the issue, @sbianda ?

Hi Andrei,
no, unfortunately not.
I have to say that the developers didnā€™t have to much time to investigate the problem.
I did some modification, but with no effect. (Iā€™m personally not a Dotnet developerā€¦)
Bye Stefano

yes, if the scanner finds test assemblies linked to the project, it will mark the project as a test project.

you can manually mark the projects as not test projects with

<SonarQubeTestProject>false</SonarQubeTestProject>

please let us know when you get more info.

Hi,
thanks for your help
we have removed the test and some entries on our csproj (see below) and now the analysis is done normally.

I didnā€™t test your solution with SonarQubeTestProject set to false, so I cannot confirm if it works

You can close the issue
Bye Stefano Bianda

Import Project=ā€œā€¦..\packages\NUnit.3.10.1\build\NUnit.propsā€ Condition=ā€œExists(ā€˜ā€¦..\packages\NUnit.3.10.1\build\NUnit.propsā€™)ā€ />

Reference Include=ā€œnunit.framework, Version=3.10.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSILā€>
ā€¦..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll

1 Like