Sonarqube not showing dotnet-coverage analysis nor unit tests metrics

the .coverage files (which are created by dotnet test) are indeed under $(Agent.TempDirectory) in some subdirectories but the bash command (actually you might need to run it on cmd or powershell if you dont have bash in your windows self-hosted build agent) will recursively search *.coverage files under $(Agent.TempDirectory) [-r argument in dotnet-coverage merge, did you check the documentation I linked? the -o argument sets the output file path ]

Yes, I have used powershell instead and applied all your recommandations, pipeline went through but 2 issues now raised.
1st one is I lost the dispaly of code coverage in Azure devops as before and can see only a link to download the analysis
image

2nd, ins spite of everthing went OK, still in sonar qube UI for the project I dont see code coverage nor unit tests

Aleksi, Some good news, with your wonderful help, and after changing some parameters and replacing some steps, all build pipeline went through and I was able to see in sonarQube the coverage results only not the unit test as you can see in last snapshot as well as still in Azure Devops Coverage tab I still see the download link instead of the report. Regarding Reportgenerator, it seems I cant use it in a classic pipeline

The parameters I used
Sonar Prepare step ; sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)/myfile.coverage.xml

Test step
–configuration $(BuildConfiguration) --collect “Code Coverage” -s $(System.DefaultWorkingDirectory)/src/runsettings.xml

Powershell step
dotnet-coverage.exe merge -o $(Agent.TempDirectory)\myfile.coverage.xml -f xml -r $(Agent.TempDirectory)/*.coverage

Publish code coverage
image

Here is the full pipeline

Also, while build pipeline was processing I managed to copy the directory which seems to me a little too much stuff created as follows

in each directory there are the 3 files

image

I have the impression that things are created twice

Anyway, here is the ouput in sonarQube which made me half-happy as still no value for unit testing

Hmm, seems like for your setup the binary .coverage files are unnecessarily. Not sure if the dotnet-coverage merge will also work for cobertura → xml convert (I guess it does).
So you could try with Test-task with -s switch you have and remove the —collect-coverage, that should give the coverage files as cobertura format if you have the XPlat in runsettings file.

Then just modify the /*.coverage/*.cobertura.xml in the powershell task. (so that you are now converting cobertura format to xml instead of binary coverage format to xml)

Sonarqube will only show the number of unit test in the UI but you need to configure that also in the prepare analysis step
The property is
sonar.cs.vstest.reportsPaths= $(Agent.TempDirectory)\**\*.trx

Edit: and in the publish code coverage task you should have $(Agent.TempDirectory)\**\*.cobertura.xml
not the myfile.coverage.xml (as it is not in cobertura format) or does it want only one file? Dont know, havent used that

Aleksi, I added
sonar.cs.vstest.reportsPaths= $(Agent.TempDirectory)***.trx
and yes, Number of unit tests dispalyed in sonar. However, switching /*.coverage/*.cobertura.xml
did not help for displaying coverage results correctly in Azure devops, only the download link, nor the coverage details in sonar UI

By the way Aleksi, is there a possibility of sending the analysis report in a readable format to the person who has commied the new code? Why I am asking this is because I have the intention to fail/stop the pipeline if more that 1blocking issue exist and would like to inform the developer right away

you only need add this step
steps:

  • task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@5
    displayName: ‘ReportGenerator to sonar’
    inputs:
    reports: ‘$(Build.SourcesDirectory)/**/TestResults/*/coverage.cobertura.xml’
    targetdir: ‘$(Agent.BuildDirectory)/sonarqubecoverage’
    reporttypes: ‘SonarQube’

Bruno, do you mean I need to remove all configs suggested by aleksi and revert back to initial usage as indicated in the previous posts, for example should I use
/.cobertura.xml instead of /*.coverage in the powershell task…
When I used /
.cobertura.xml did not help for displaying coverage results correctly in Azure devops, only the download link, nor the coverage details in sonar UI