# Sonarqube not showing dotnet-coverage analysis nor unit tests metrics

**URL:** <https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801>\
**Category:** SonarQube Server / Community Build\
**Tags:** coverage\
**Created:** [October 20, 2022, 8:18am UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801 "2022-10-20T08:18:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 20, 2022, 8:18am UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/1 "2022-10-20T08:18:17Z")

</div>

Hi, I have a pipeline where I introduced, according to instructions at  
[.NET Test Coverage | SonarQube Docs](https://docs.sonarqube.org/latest/analysis/test-coverage/dotnet-test-coverage/) chapter “Extension for Azure Devops” it is indicated

arguments: ‘–collect “Code Coverage”’ # This is all you need to add!  
in the test stage  
Pipeline configured as follows

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/6/f/6f59aa6f25b041a519cd0784b0fbf42665579423.png)

here is the test step

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/2/7/27042f59de4a187ad67c453f09aadb210700813e.png)

jobs run successfully

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/a/1/a13fbb73c729f2654bb25b9626f7c3ddbe8d807d.jpeg)

but nothing is shown on the sonarqube project page regarding coverage not test units reports

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/e/8/e8b45567daf5e892196752abdb255b3e6078671c.png)

Am I missing something?

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [October 21, 2022, 1:24pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/2 "2022-10-21T13:24:40Z")

</div>

What do the logs say?

> [@How to find logs about importing code coverage](https://community.sonarsource.com/t/how-to-find-logs-about-importing-code-coverage/73317):
>
> When coverage data isn’t appearing as expected in SonarQube Server / Community Build or SonarQube Cloud, the first place you should look is the scanner logs. Where do I find the scanner logs?warning This will likely be broken out into its own guide soon The Scanner logs are the output of executing one of the [scanners](https://docs.sonarqube.org/latest/analysis/overview/), either directly or wrapped by one of many integrations, such as the [SonarScanner for Jenkins](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/), [SonarScanner for Azure DevOps](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-azure-devops/), [SonarQube](https://github.com/SonarSource/sonarqube-scan-action)/[SonarCloud](https://github.com/marketplace/actions/sonarcloud-scan) GitHub Actions or [SonarQube](https://bitbucket.org/sonarsource/sonarqube-scan/src/master/) /…

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 21, 2022, 2:17pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/3 "2022-10-21T14:17:52Z")

</div>

I have visited the link [SonarScanner for Azure DevOps](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-azure-devops/)  
but nowhere it is indicated where I can find the log files  
I have setup the scanner using on the build agent

```auto
dotnet tool install --global dotnet-sonarscanner

```

and the following extension is setup on AzureDevops Server  
[SonarQube - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube)

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [October 21, 2022, 2:36pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/4 "2022-10-21T14:36:31Z")

</div>

![Screenshot 2022-10-21 at 16.36.07](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/c/5/c5702f473078f896c44a97d83709e023e2e00b7b.jpeg)

Right there.

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 21, 2022, 5:07pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/5 "2022-10-21T17:07:26Z")

</div>

OK, got it I thought you were talking about other logs. Anyway, tests are run correctly, coverage repor is created as you can notice in the snapshot , even I added “Publish code coverage from”

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/b/d/bd0bfc26419d84c7b22a614f30f4193f38f7309d.png)

![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/6/b/6bcb0c86e538185f876a5456d34c6ede05a74e79.png)

Also, I found this error in the “Run Code Analysis” step

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/9/0/9076e892a391a0fd018375f40ecca31ba9acad4c.png)

in spite of the fact that dotnet-cover is setup and when I run it on command line it works, of course on the building agent and not on the sonarQube server? Should this be running on the soanrqube server !!!

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [October 24, 2022, 12:12pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/6 "2022-10-24T12:12:51Z")

</div>

Hey there.

The scanner does require [Microsoft.CodeCoverage.Console tool](https://learn.microsoft.com/en-us/visualstudio/test/microsoft-code-coverage-console-tool?view=vs-2022) to be available on the machine performing analysis in order to convert/merge test reports.

Are you using self-hosted build agents? What version of Visual Studio is installed, and what edition?

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 24, 2022, 7:39pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/7 "2022-10-24T19:39:17Z")

</div>

Yes, I use self-hosted which is on a win 10 physical machine. I have Visual Studio Professional, I am aware of the fact that coverage feature is in Enterprise edition, however, that is why when I read instructions at [.NET Test Coverage | SonarQube Docs](https://docs.sonarqube.org/latest/analysis/test-coverage/dotnet-test-coverage/)  
I understood that this can allow to not need Enterprise edition and that is why it is installed globally? Non?

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 26, 2022, 5:27pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/8 "2022-10-26T17:27:31Z")

</div>

Colin, after a long discussion on the github project for Coverlet at

> <https://github.com/coverlet-coverage/coverlet/issues/1399>
>
> HI,
> Can you please tell me why coverlet-coverage creates coverage files inside …the \_temp directory of the build agent and not in System.DefaultWorkingDirectory.
> The \_temp directory is a place for all working directories for all pipelines so if 2 pipelines run at the same time, and coverlet-coverage uses this directory, how concurrency/identification to which pipline the coverage file belong to which pipeline will happen?
> Thanks

petli very nice guy and really helped a lot. After a succesful run of the build pipeline, were created correctly and I was able to see nice reports inside Azure devops, I switched to sonarQube UI, still I see that sonarqube gets alerted of the new build but does not display coverage and unt test details. After investigating, I discovered that Azure devops creates coverage reports in the \_temp directory of the build agent and not the project working directory which seems that sonarQube task does not search this upper directory (I came this thread which confimed this)across this thread

> <https://github.com/microsoft/azure-pipelines-tasks/issues/11536>
>
> \*Type\*: Feature
> 
> \*\*Enter Task Name\*\*: .NET Core - test
> 
> \## Environment
> Serv…er - Azure Pipelines
> 
> \## Issue Description
> 
> Checking the \*\*Publish test results and code coverage\*\* option sets --results-directory to the agent's temporary directory, making it difficult to isolate a single build's test output when publishing the results of multiple data collectors.
> 
> Recommendation: Allow --results-directory to be overridden (via textbox) when \*\*Publish test results and code coverage\*\* is checked.
> 
> This would allow users to harvest the output for publishing to additional code coverage tools or overcome shortcomings in the existing tooling (such as the code coverage tab only providing a link instead of an html report).

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/0/1/01d536646179ef0a861306f42fad7e4e1a21916d.png)

So the question : where in the chain or project we can tell sonarQube to search other directories for coverage code?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![StingyJack](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/stingyjack/32/13336_2.png) [@StingyJack](https://community.sonarsource.com/u/StingyJack)\
**Post date:** [October 26, 2022, 10:22pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/9 "2022-10-26T22:22:29Z")

</div>

I felt a pull in The Force, as if someone had said my name. =D

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 27, 2022, 6:48am UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/10 "2022-10-27T06:48:23Z")

</div>

I dont really understand this response!!!

---

<div class="post-metadata">

**Author:** ![StingyJack](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/stingyjack/32/13336_2.png) [@StingyJack](https://community.sonarsource.com/u/StingyJack)\
**Post date:** [October 27, 2022, 4:51pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/11 "2022-10-27T16:51:03Z")

</div>

You pasted a screenshot of a github issue I had reported in this issue. I was not tagged or mentioned.

Less than 5 hours later I find myself looking at this thread, Probably just coincidence.

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 27, 2022, 6:36pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/12 "2022-10-27T18:36:39Z")

</div>

Or maybe I should ask the question differently, Is there a a parameter/Config in Sonarqube extension for Azure devops to tell it what is the location of the reports?

---

<div class="post-metadata">

**Author:** ![Dahlorna](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@Dahlorna](https://community.sonarsource.com/u/Dahlorna)\
**Post date:** [October 28, 2022, 10:39am UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/13 "2022-10-28T10:39:43Z")

</div>

Hi,

If I understood correctly you dont have Visual Studio Enterprise version in your self-hosted build agent, so you need to use dotnet-coverage tool (for example). The dotnet-coverage will convert .converage format to .xml format and you need to tell sonarscanner where is the xml file. See sonar.cs.vscoveragexml.reportsPaths  
in [Test Coverage Parameters | SonarQube Docs](https://docs.sonarqube.org/latest/analysis/test-coverage/test-coverage-parameters/)

So in your **SonarQubePrepare** -task you will need to add in **extraProperties** following:  
`sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)/myfile.coverage.xml` (for the path see the -o parameter in bash script below)

In your **Test** -task either add following argument  
`--results-directory $(Agent.TempDirectory)` (or any folder you want) or do that in the .runsettings file

The .coverage files are seperated by the test cases and need to be merged and converted to one xml-file, so after **Test** -task add following bash script task to merge (-r argument) and convert (-f argument) .coverage files

```auto
      - bash: dotnet-coverage merge -o $(Agent.TempDirectory)/myfile.coverage.xml -f xml -r $(Agent.TempDirectory)/*.coverage
        displayName: 'Convert coverages to xml'

```

hope this helped =)

Edit: maybe merging to one xml file is not mandatory (so you could have multiple xml files) but that is what I ended with

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 28, 2022, 12:23pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/14 "2022-10-28T12:23:25Z")

</div>

so many thanks Aleski, I tried something likethis

> sonar.projectBaseDir=$(Agent.TempDirectory)\*\*\coverage.cobertura.xml(this is the way \*\* that azure devops reference su-directoris as the ml file is generated in temporary subdirectories and not directly in the \_temp directoy)

in the prepare step but sonar gives an error, 2nd snapshot is for the error, indicating illegal carater, I tied to enclose with double quotes but also refuses

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/e/a/ea29d8f543c8980286785395c72027407c39e272.png)

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/6/f/6f147c97a0b65423e8c17727deb7ffa8a6f57418.png)

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/8/c/8c2ca3a17fcce631a49bfbcf51b7512f5440dbb3.png)

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/d/5/d575675bef7e0641f419b3d502ad34b6c1da0647.png)

as well as other test but they all fail;ed because of the 2 or 1 asterk

Is there a possiblity o make understand that \*\* is meant should look in subdirectories?

Because it shoud be inerpreted as  
C:\Projects\agent-

> AzureDevOps2K20Update15\_work\_temp\2321254\coverage\coverage.cobertura.xml

The 2321254 directory is reatredon the fly dynaically by the bild process

---

<div class="post-metadata">

**Author:** ![Dahlorna](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@Dahlorna](https://community.sonarsource.com/u/Dahlorna)\
**Post date:** [October 28, 2022, 12:35pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/15 "2022-10-28T12:35:57Z")

</div>

You are using wrong config value in you prepare analysis step.

so change `sonar.projectBaseDir` → `sonar.cs.vscoveragexml.reportsPaths`

and I’m not sure does SonarQube support cobertura xml format for C#, that is why I’m using xml format and that `sonar.cs.vscoveragexml.reportsPaths` config value.

so cobertura xml is different than (vscoverage)xml imho. See for example  
[dotnet-coverage code coverage tool - .NET CLI - .NET | Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-coverage#dotnet-coverage-merge)

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 28, 2022, 1:22pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/16 "2022-10-28T13:22:43Z")

</div>

Here is the structure of the \_temp directory during uild process

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/1/5/1593ebd6709915a54ebe6528bc80e71e1beaef3d.png)

> [@Dahlorna](#):
>
> –results-directory

as soon as I add --results-directory to test step the test step it fails.  
so I removed

I replaced sonar.projectBaseDir by sonar.cs.vscoveragexml.reportsPaths and ran the build pipeline

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/3/c/3c433d7e416a44d13a68d2715a90f690c029a7da.png)

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 28, 2022, 1:28pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/17 "2022-10-28T13:28:52Z")

</div>

Ok, after removing results directory from test step and keeping sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)\*\*\coverage.cobertura.xml  
in prepare step, build goes through but it seems there is an issue sonar acceptig self-igne certificate as follows

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/1/1/11ba706516293c7f0dcd035c1b2a7acece22060e.png)

and thisis the error on sonar server side, is it possible to tellsonar not to validate certificate? however my certifdicate is accepted b google and edge without any issues

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/0/a/0aee4bb5f55a6472dd42a702fe2cf2cfbb0edf15.png)

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 28, 2022, 1:32pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/18 "2022-10-28T13:32:42Z")

</div>

Regarding the format, MS guys on community confirmed that I should use

–collect:“XPlat Code Coverage”

---

<div class="post-metadata">

**Author:** ![Dahlorna](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@Dahlorna](https://community.sonarsource.com/u/Dahlorna)\
**Post date:** [October 28, 2022, 2:07pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/19 "2022-10-28T14:07:12Z")

</div>

I guess they didn’t. They just gave you an example runsettings file where was XPlat Code Coverage specified and the last comment was  
“The issues you have now is something with how your build system runs your tasks, and I can’t assist with that. For sonarqube you have to read their documentation on how to specify the coverage report path. You may find [https://reportgenerator.io/](https://reportgenerator.io/) **useful if you need to convert between report formats or if you have multiple coverlet output files that must be merged into a single report**.”

But now I remember that I also had problems with those DotNetCoreTasks which you are using (I’m using YAML pipelines anyways and not the classic UI defined pipelines).  
So the Test-task actually incjects to --logger trx and --results-directory arguments to the dotnet test command what you see in your logs it can be seen from Info icon next to ‘Publish test results and code coverage’

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/5/7/57f545f9ddfa9276b3a91b55dec19120079eb26c.png)

so if you use that the reports are always going to $(Agent.TempDirectory).

I would recommend to change back to `--collect "Code coverage"` setting, adding the bash script task with following command  
`dotnet-coverage merge -o $(Agent.TempDirectory)/myfile.coverage.xml -f xml -r $(Agent.TempDirectory)/*.coverage`

and setting in prepare analysis  
`sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)/myfile.coverage.xml` (NOTE: specific file that we do with bash script)

For the certificate error in Publish Quality Gate results you need to add correct certificate chain to your self-hosted build agent’s Trusted Certs.

Hope this helps you, have a nice weekend!

---

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://community.sonarsource.com/u/eliassal)\
**Post date:** [October 28, 2022, 2:21pm UTC](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801/20 "2022-10-28T14:21:41Z")

</div>

Ok I will update the build pipeline with your suggestion but can you tell me how it will find  
myfile.coverage.xml  
which is not directly under $(Agent.TempDirectory)? it is a lower level directory created on the fly as the screenshot I posted earlier

[Next page](https://community.sonarsource.com/t/sonarqube-not-showing-dotnet-coverage-analysis-nor-unit-tests-metrics/74801.md?page=2)
