C# MSBuild The main branch has no lines of code

Template for a good new topic, formatted with Markdown:

  • ALM used - Azure Devops
  • CI system used - Azure DevOps
  • Languages of the repository - C#

task: SonarCloudPrepare@1
displayName: ‘SonarCloud configuration’
SonarCloud: ‘SonarCloud’
organization: ‘companyname’
scannerMode: ‘MSBuild’
projectKey: ‘companyname.projectname’
projectName: ‘projectname’
extraProperties: |
sonar.cs.xunit.reportsPaths={Agent.TempDirectory}/**/XUnit.TestResults.xml sonar.cs.opencover.reportsPaths={Agent.TempDirectory}/

Scanner is running, but finding zero files, Sonar cloud page is showing no files in the project, but I can navigate to the files within Sonarcloud, and it can show me what changed in the pull requests I’ve created, but ignores the obvious smells I planted in there.

Using an older VS project format, with tools version set to 12. Project contains only c#, nothing out of the ordinary.

We have other, similar c# projects that are being analysis correctly, so I’m a bit stumped by this one.

Hi @Paul_Horton and welcome to the community !

Can you try running the scanner once again, with debug mode enabled (system.debug to “true”) and seek for the Run Code analysis task logs.

There should be an output of the sonar-project.properties files that is generated by the scanner. Can you please have a look at every sonar.sources property set (no matter which guid is in front of) and see if you find your files ?


Hello @mickaelcaro,

Just ran it with debug and all of the sonar.sources are either empty or a single \

Interestingly, the scanners find the files in the source project but mark them as test files. We’ve not configured anything to exclude any of the unit tests at this point.

Hey @mickaelcaro, I think we’ve just found it…

Like I say, it’s an older project and had some strange explicit references to some xUnit libraries, as well as some props files and strange things. Seems like this was confusing the scanners as we’ve removed those references (we don’t know why they were there!!) and it all starts working.

Well thank you for your time, sorry we didn’t get to this before bothering you :slight_smile:

That’s cool to read !

I don’t know if you stambled accross already, but we wrote a bit of documentation on how we categorize projects here : https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects

That can help for the future !


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