# C# Code Coverage with Team City integration

**URL:** <https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112>\
**Category:** SonarQube Server / Community Build\
**Tags:** teamcity, csharp, sonarqube\
**Created:** [June 24, 2019, 2:23pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112 "2019-06-24T14:23:50Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![beik](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@beik](https://community.sonarsource.com/u/beik)\
**Post date:** [June 24, 2019, 2:23pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/1 "2019-06-24T14:23:50Z")

</div>

Hello,

I am new to the SonarQube product. To date, we have configured the sonarqube server, the SQL database and integrated the sonarqube runner with team city. We currently have a C#/.NET project that I am attempting to scan. In the scan results, it is showing 0.0 Code Coverage. This codebase is predominately C#/.NET along with some javascript and HTML. In the documentation, [https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild](https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild) , it states how to setup sonarqube for MSBuild however we are using team city to build the package. I have followed this link for the team city, sonarqube integration.[https://confluence.jetbrains.com/display/TW/SonarQube+Integration#SonarQubeIntegration-ReSharperinspections(Inspections(.NET)runner](https://confluence.jetbrains.com/display/TW/SonarQube+Integration#SonarQubeIntegration-ReSharperinspections(Inspections(.NET)runner))  
I am wondering what steps need to be taken in order to gain code coverage on the package. Any help or guidance in the would be appreciated. Thank you.

---

<div class="post-metadata">

**Author:** ![scmbuildguy](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/scmbuildguy/32/4767_2.png) [@scmbuildguy](https://community.sonarsource.com/u/scmbuildguy)\
**Post date:** [June 24, 2019, 4:59pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/2 "2019-06-24T16:59:32Z")

</div>

Hi Sam,

Are you running a code coverage tool, such as OpenCover, when executing your tests? See the Sonarqube documentation for importing code coverage results, [https://docs.sonarqube.org/pages/viewpage.action?pageId=6389770](https://docs.sonarqube.org/pages/viewpage.action?pageId=6389770).

Hope that helps,

–Mark

---

<div class="post-metadata">

**Author:** ![beik](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@beik](https://community.sonarsource.com/u/beik)\
**Post date:** [June 24, 2019, 6:14pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/3 "2019-06-24T18:14:41Z")

</div>

Mark,

Thanks for the response. That’s what I don’t quite get. This is being run though (automated ) Team City. The documentation for team city is here: [https://confluence.jetbrains.com/display/TW/SonarQube+Integration#SonarQubeIntegration-dotCoverresults](https://confluence.jetbrains.com/display/TW/SonarQube+Integration#SonarQubeIntegration-dotCoverresults) . In reading the documentation you sent me, it looks like for MSBuild is set to: `sonar.cs.vscoveragexml.it.reportsPaths` , Visual Studio is set to: `sonar.cs.vscoveragexml.reportsPaths= **"%CD%\VisualStudio.coveragexml`, docCover is set to: etc. The setting I have in Team City is `Dsonar.resharper.cs.reportPath=%system.teamcity.build.tempDir%\inspectReport.xml`.

This setting within TC should complete the code coverage correct?

---

<div class="post-metadata">

**Author:** ![scmbuildguy](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/scmbuildguy/32/4767_2.png) [@scmbuildguy](https://community.sonarsource.com/u/scmbuildguy)\
**Post date:** [June 24, 2019, 7:52pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/4 "2019-06-24T19:52:35Z")

</div>

Been a while since I have used Team City, however, the property you are using is for the ReSharper static code analyzer, not the property for Code Coverage with DotCover.

I found this page, [https://confluence.jetbrains.com/display/TW/Integrating+TeamCity+dotCover+Report+with+SonarQube+Runner](https://confluence.jetbrains.com/display/TW/Integrating+TeamCity+dotCover+Report+with+SonarQube+Runner), for integrating DotCover with SonarQube Scanner. I think the SonarQube property you want to use is ‘sonar.cs.dotcover.reportsPaths’.

–Mark

---

<div class="post-metadata">

**Author:** ![Andrei\_Epure](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andrei_epure/32/77402_2.png) [@Andrei\_Epure](https://community.sonarsource.com/u/Andrei_Epure)\
**Post date:** [July 1, 2019, 2:37pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/5 "2019-07-01T14:37:28Z")

</div>

thanks a lot, @scmbuildguy, for your valuable replies.

@beik - did you manage to import the code coverage?

---

<div class="post-metadata">

**Author:** ![beik](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@beik](https://community.sonarsource.com/u/beik)\
**Post date:** [July 3, 2019, 1:59pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/6 "2019-07-03T13:59:24Z")

</div>

Andrei,

Not yet. I am going to run some tests today to see if i can get it working. I will update this with findings.

---

<div class="post-metadata">

**Author:** ![Andrei\_Epure](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andrei_epure/32/77402_2.png) [@Andrei\_Epure](https://community.sonarsource.com/u/Andrei_Epure)\
**Post date:** [July 24, 2019, 3:44pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/7 "2019-07-24T15:44:10Z")

</div>

hi @beik - any update on this, did you manage to make it work?

---

<div class="post-metadata">

**Author:** ![beik](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@beik](https://community.sonarsource.com/u/beik)\
**Post date:** [July 26, 2019, 1:47pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/8 "2019-07-26T13:47:38Z")

</div>

Andrei,

Through a lot of trial and error, we were able to get the test execution and unit tests running with dotCover. Reports are being generated, merged and being picked up by Sonarqube. The issue now is that Sonarqube is not reading the code coverage portion of it. Under code coverage, it shows “-”??

---

<div class="post-metadata">

**Author:** ![beik](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@beik](https://community.sonarsource.com/u/beik)\
**Post date:** [July 26, 2019, 5:59pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/9 "2019-07-26T17:59:51Z")

</div>

So it looks like it is providing coverage on the javascript and css files but not the C# files. in the build log, it is showing that the C# files are being scanned but that is not being populated in sonarqube??

---

<div class="post-metadata">

**Author:** ![Andrei\_Epure](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andrei_epure/32/77402_2.png) [@Andrei\_Epure](https://community.sonarsource.com/u/Andrei_Epure)\
**Post date:** [July 31, 2019, 2:15pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/10 "2019-07-31T14:15:46Z")

</div>

> [@beik](#):
>
> it is showing that the C# files are being scanned

Please run it with diagnostics turned on - add the `/d:sonar.verbose=true` at the _BEGIN_ step.

Then please upload here the logs of the _END_ step.

---

<div class="post-metadata">

**Author:** ![beik](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@beik](https://community.sonarsource.com/u/beik)\
**Post date:** [July 31, 2019, 3:35pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/11 "2019-07-31T15:35:33Z")

</div>

Andrei,

Attached are 2 files. There is one with out the final build step, which is to send to sonarquube anad one with the end build step, send to sonarqube, that fails build. In that log file, there is an error message regarding begin and end step. Documention is iffy and what exactly those steps are supposed to be comprised of? Thank you for your continued help.

[development\_w\_final\_142.txt](https://community.sonarsource.com/uploads/short-url/w4yViE4KSeB0Uas0UAJBaKqBviG.txt) (299.7 KB)

[development\_wo\_final\_141.txt](https://community.sonarsource.com/uploads/short-url/4mDzgyjJfvaRqn7ze6QUaIph07W.txt) (296.8 KB)

---

<div class="post-metadata">

**Author:** ![beik](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@beik](https://community.sonarsource.com/u/beik)\
**Post date:** [August 1, 2019, 3:10pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/12 "2019-08-01T15:10:37Z")

</div>

Andrei,

Below are the screenshots showing the build process as a whole and the steps setting within the begin and end. I am hoping to verify that everything is correct. Thank you.

 ![Team%20City%20Build%20Steps](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/c/c60cbf1e9a2e5b674d3cbdb1ce290184a264c820.png)

---

<div class="post-metadata">

**Author:** ![beik](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@beik](https://community.sonarsource.com/u/beik)\
**Post date:** [August 1, 2019, 3:11pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/13 "2019-08-01T15:11:14Z")

</div>

![Team%20City%20Sonar%20Begin](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/4/4749314981e2e250260384a9bbb64695639f3303.png)

---

<div class="post-metadata">

**Author:** ![beik](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@beik](https://community.sonarsource.com/u/beik)\
**Post date:** [August 1, 2019, 3:12pm UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/14 "2019-08-01T15:12:02Z")

</div>

![Team%20City%20Sonar%20End](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/2X/8/8e4ba6ea288d41b0ca8c19ffcfdc9cb5cb5d19a8.png)

---

<div class="post-metadata">

**Author:** ![duncanp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/duncanp/32/293_2.png) [@duncanp](https://community.sonarsource.com/u/duncanp)\
**Post date:** [August 9, 2019, 11:45am UTC](https://community.sonarsource.com/t/c-code-coverage-with-team-city-integration/11112/15 "2019-08-09T11:45:41Z")

</div>

@beik could you post a link to the iffy documentation please? If it’s our documentation we can fix it; if it’s for the third-party TeamCity plugin we can’t.

Looking at the failing log, the scanner `begin` step is immediately followed by the scanner `end` step. That isn’t how the scanner is intended to be run. The expected sequence is:

1. scanner `begin`
2. execute the build and test
3. scanner `end`

There is more information in the docs for the Scanner for MSBuild [here](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/).

_EDIT: the ordering in the screenshots looks ok, but doesn’t match what’s in the log files:_

```auto
[10:22:27]W: Step 3/6: Build Payment (Visual Studio (sln)) (22s)
...
[10:28:00] : Step 4/6: Execute Unit Tests (Visual Studio Tests) (13s)
...
[10:28:14] : Step 5/6: Static Code Analysis (SonarScanner for MSBuild: begin analysis) (1s)
...
[10:28:15]E: Step 6/6: Complete SonarQube Report (SonarScanner for MSBuild: finish analysis)

```

I’m not familiar with either TeamCity or the TeamCity plugin for SonarQube (although I see the plugin is using v4.0.2 of the scanner which is rather old and doesn’t support either the new SDK-style MSBuild project format or MSBuild v16).

However, the scanner is just a command line tool, and the plugin is just a wrapper around the scanner that is intended to make it easier to provision the scanner onto your build agents and then invoke it for you. Looking at the docs for the scanner should give some pointers on how it you should configure the plugin i.e. the ordering of tasks, and the parameters to pass at each stage.

Alternately, if the plugin isn’t helping you then you could just call the scanner directly from script code in your build pipeline.
