Main files classified as test files. Target "SonarCategoriseProject" skipped with SonarQubeTestProject flag

Hello everyone. I have just started to test Sonarqube with Unity. After finishing the scan, I did not get much information as my prod code is defined as Test per the warning in the dashboard and in the logs:

WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. Only TEST-code related results will be imported to your SonarQube/SonarCloud project. 
Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. 
Read more about how the SonarScanner for .NET detects test projects:

After visiting the forums and read the documentation, I added the TestProject flag to the csproj file, but that has not changed things:

  <!-- Project is not a test project -->

I have seen that you can check how and why it was categorized, but I cannot find the info in my rebuild logs (rebuild command per .NET Framework invocation), the only line that I find with the SonarCategoriseProject said is being skipped (as far as I understood). Would you think is not trying to re-categorize because is skipping it? And if it is, would you advise me on how could I make it not skip?

Target "SonarCategoriseProject" skipped. Previously built successfully.

This is the config I’m using to run Sonarqube:

  • Language: C#
  • Sonarqube:
  • Scanner: MSBuild
  • .NET Framework Invocation
  • Process: Manual
  • Special things: I had to modify around 20 projects to be ignored, as Unity creates multiple of these.

Scanner commands:

[Scannerlocation]\SonarScanner.MSBuild.exe begin /k:"MyKey" /"http://localhost:9000" /d:sonar.login="token"

"[VSlocation]\MsBuild.exe" SolutionName.sln /t:Rebuild /v:diag

[Scannerlocation].MSBuild.exe end /d:sonar.login="token"

I ran the begin /d:sonar.verbose=true, and I noticed this on the end logs for a lot of the files within the main project, and I would assume all of them?:

08:48:42.581 DEBUG: 'Assets/Scripts/Items/Gear/GearType.cs' generated metadata as test  with charset 'UTF-8'
08:48:42.581 DEBUG: 'Assets\Scripts\Items\Gear\GearType.cs' indexed as test with language 'cs'

I was able to fix it :slight_smile: !

First I ran the build with the Clean parameter to create a new verbose build (after figuring out that was a thing). That new build allowed me to see how the projects were being classified, and I found the problem. The cmd:

"[VSlocation]\MsBuild.exe" SolutionName.sln /t:Clean;Rebuild /v:n

After this, I noticed that I had the Nsubstitute reference within the project, but I thought the “SonarCategoriseProject” property took priority. That’s when I realized that the project that Sonarqube was taking was a different one.

On Unity, if you want to start doing Unit-test, you need to create assembly definitions (they are not created by default). So Unity had two projects, the “main” one, which has the same name as the solution, and then the assembly definition that I had created. I had added the property to the “main” one, but Sonarqube was using the one in the assembly definition. I just added the property to the assembly definition one and that worked out!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.