For a long time I wanted to integrated NDepend on our build server so that this week I invested some time here and there to achieve that goal. I did that already a long time ago, I even wrote the documentation which you can read on NDepend website.

This time I wanted to go one step further.

We use a first build which is building each feature branch we are developing. One of the responsibility of that build is to run unit tests, integrations tests, specifications and gather code coverage. To achieve that we are using the TeamCity integrated dotCover in each build steps running our different tests. This is collecting artifacts which aren’t directly shown on the Artifacts tab:

Clicking show reveal the file we are interested about, dotCover.snapshot:

Something to note is that to be able to use code coverage NDepend needs the pdb files, this is why we have another artifact named And finally the third is our software with the exe and dlls.

Now that we have a build which generate the coverage file which we want to pass to NDepend, let’s create another TeamCity build which will define Snapshot Dependency and Artifact Dependency to the previous build:

We are extracting the exe to a NDepend folder and all dlls out of the archive Libs folder to the same NDepend folder.
We do the same for the pdb files so that NDepend can use the code coverage data.
Finally we extract the dotCover.snapshot to a dotCover folder.

Then the issue we had was that the dotCover.snapshot file is not of the format that NDepend is expecting.

So as a first build step of our NDepend build we need to convert dotCover.snapshot file, this is done using a Command Line build step and dotCover integrated in TeamCity, using the report command and the ReportType equal to NDependXML:

So after that build first step we have a new converted file; dotCoverNDepend.xml which can be consumed by NDepend.

Then in the second build step we are using dotCoverNDepend.xml with the new NDepend 5.1 CoverageFiles command parameter:

Here is the full command

C:\NDepend\NDepend.Console.exe “\skyeEditor.ndproj” /CoverageFiles “\dotCover\dotCoverNDepend.xml” /InDirs “\NDepend” “C:\Windows\Microsoft.NET\Framework\v4.0.30319” “C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF” /OutDir “C:\NDependOutput”

This will create the NDepend report which we will archive as an artifact, on the General Settings of the build

Then you will need to define that you want to see the NDepend report as a TeamCity Report Tab, which you define by navigating to Administration > Report Tabs, clicking Create new report tab and specifying

Finally you will have the following NDepend report with code coverage shown for your builds

One last thing I struggled about is that the NDepend builds were not started, because I thought it was enough to configure the Dependencies, but you need to define also a Build Trigger with Trigger on changes in snapshot dependencies ticked:

Thanks to **Yegor **for the discussion which greatly helped as always! And also to Ruslan which also helped through the post on the jetbrains forum. And finally thanks to Patrick who introduced really fast the /CoverageFiles in NDepend, so do not hesitate to give feedback using the new NDepend user voice.