MSBuild scan no longer scanning any .cs files

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Scanner command used when applicable (private details masked)
- task: SonarCloudPrepare@1
  displayName: 'SonarCloud - Prepare analysis'
  inputs:
    SonarCloud: ${{parameters.sonarCloudServiceConnection}}
    organization: ${{parameters.sonarOrganization}}
    scannerMode: 'MSBuild'
    projectKey: ${{parameters.sonarProjectKey}}
    projectName: ${{parameters.sonarProjectName}}
    extraProperties: | 
      sonar.cs.vstest.reportsPaths=**/*.trx                       
      sonar.cs.opencover.reportsPaths=**/*.opencover.xml        
      sonar.coverage.exclusions=**/*Controller.cs
      sonar.exclusions=**/Migrations/**/*.cs,**/PackageRoot/**/*,**/Swagger/**/*,**/appsettings*.json,**/*.Service.xml,**/Data/**/SeedData/**/*,**/Data/**/Seed*.cs
  • Languages of the repository: C# primarily
  • Error observed:
    On a couple of our projects, we’ve experienced a massive drop in LoC analyzed. It looks like it’s excluded *.cs and only some leftover XML and CSS files are analyzed.

When navigating the project in the portal I do see the .cs files, but they are listed with - LoC

I’ve tried disabling the sonar.exclusions and sonar.coverage.exclusions properties and re-run the scan, but it had the same result.

It started with 1 project, but it looks like it’s “spreading”, as 8 of them now show this behavior.

Any ideas on what could be wrong?

Update 1:
I just tried deleting and recreating the project, but that ended up with the same result.

Update 2:
I’ve been looking at the ProjectInfo.log files and I noticed that it marks all of the .csproj files as "Test projects, while actually only 1 is a test project:

How does SonarCloud determine what is/isn’t a test project?

@AdeZwart this page explains how the scanner categorises projects: Analysis of product projects vs. test projects · SonarSource/sonar-scanner-msbuild Wiki · GitHub

1 Like

Thanks @duncanp, this was exactly what I needed to find the solution!

I learned a lot from those docs and found out that someone actually added moq to some code that was shared between some of our projects. Based on this SonarCloud categorized all of it as testing code, while it actually wasn’t.

After finally finding it, it was easily resolved.

Thanks again!

1 Like

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