Code Coverage for .Net Framework C# code

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarScanner for MSBuild 5.7.2
    C# code
    .Net Framework 4.7
    Console application

using the below cmd for execution…

SonarScanner.MSBuild.exe begin /k:"ProjectName" /d:sonar.login=abcdefgh
MSBuild.exe ProjectNameSolution.sln /t:Rebuild
SonarScanner.MSBuild.exe end /d:sonar.login=abcdefgh
  • what are you trying to achieve
    Update the code coverage on SonarQube report site.
    It remains 0.0 % all the time.

  • what have you tried so far to achieve this
    tried dotnet but results remains the same.

not sure what I am missing.

kindly help.

Thanks.

Hi,

Welcome to the community!

You need to execute the tests & generate coverage data between the begin and end steps, presumably after the build. :smiley:

The docs should help.

 
HTH,
Ann

Hi G Ann,

Yes I have followed them. and still no success. Let me know where I got it wrong.

SonarScanner.MSBuild.exe begin /k:"ProjectName" /d:sonar.login=abcdefgh /d:sonar.cs.vstest.reportsPaths=\\TestResults\\.trx /d:sonar.cs.vscoveragexml.reportsPaths=\**\TestResults\.Coveragexml
dotnet build --no-incremental
dotnet test --collect "Code Coverage"
SonarScanner.MSBuild.exe end /d:sonar.login=abcdefgh

Hi,

Perhaps the Troubleshooting guide will help.

 
Ann