02 March 2011 NDepend, TeamCity CI Team

imageNDepend is a tool which is created to detect depending´s between .NET components. The whole thing exists as Fatclient, which is perfect to integrate in Visual Studio. And there is a console application which you are able to integrate into your Buildprocess to create Reports. How this works I´m going to tell you now....

What do we need?

For the first step of creation of NDepent files and a better analysis a Fatclient is a Must-Have. But in fact, I don´t think that everyone needs to install the tool. I focus on NDepend in the Buildprocess so:

More important is to install it on the Buildserver Smiley

A little hint for NDepend: You need to license this tool for every developer and for every Build machine. More details you will find on the NDepend web page.

NDepend Quickstart

A nice declaration about how to quickstart NDepend you will find in this video.

What we need now is the .ndproj file. This is what we should have in the end as result. On our BizzBingo.com project (Codeplex) we´ve integrated it into the SLN:

imageThe ndproj describes all of the adjustments NDepend has made for this project. It´s an XML file.

To get a feeling for this file here is a very very short view into it:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<NDepend AppName="BusinessBingo" Platform="DotNet">
  <OutputDir KeepHistoric="True" KeepXmlFiles="True">C:\TFS\bb\Main\Source\NDependOut</OutputDir>
  <Assemblies>
    <Name>BusinessBingo.Data</Name>
    <Name>BusinessBingo.Model</Name>
	<Name>ASSEMBLIES...</Name>
	...
  </Assemblies>
  <FrameworkAssemblies />
  <Dirs>
	<Dir>INPUT DIRs</Dir>
    <Dir>C:\Windows\Microsoft.NET\Framework\v4.0.30319</Dir>
  </Dirs>
  ...
  <CQLQueries...>
</NDepend>

- Assemblies: All .NET Assemblies, which are recognized by NDepend for the addictions

- Dirs: This one describes the folders where the assemblies are in

- Than we have some more adjustments but they are not important at the moment

- The CQLQueries define the codemetrics and if they should be handled as "warnings" or "errors". But this doesen´t matter anyway Zwinkerndes Smiley 

Team City

At the moment NDepend runes by Night Build in our BizzBingo project. The Nightly Build is parted into four different steps

1. Build SLN

2. NUnit

3. NDepend

4. Duplicate Finder

image

For Ndepend the main important things are a) building and b) running the console program. For the analyses I need the assemblies and build the SLN. I know, that´s not the easiest way but it is okay:

image

Now NDepend is involved. If you install the version for your build machine you will also receive the console program. You are able to pass some adjustments to the console program as parameters like for example the "source directory" for the assemblies or the "target directory" for the generated report. In TeamCity it will look like that:

image

Command: (depending on where you install it)

"C:\NDepend\NDepend.Console.exe"

Parameters:

"%system.teamcity.build.checkoutDir%\Main\Docs\CodeQuality\BusinessBingo.ndproj" /OutDir "%system.teamcity.build.checkoutDir%\NDependOut" /InDirs "%system.teamcity.build.checkoutDir%\Main\Source\BusinessBingo\Source\BusinessBingo.Web\bin\"

- The first parameter shows you where .ndproj is localised %system.teacity.build.checkoutDir% takes the place before TeamCity is going to replace it during the building process.

- As OutDir I enter "NDependOut" into the checkoutDir

- As InDir I enter the bin directory of the web application - of course it´s possible to link to several other folders

TeamCity artifacts and integrating the NDepend report

After we have finished the attachment we are going to talk about the artifacts in TeamCity. An artifact could be nearly everything: an assembly, a picture, an HTML template and so on...

image

On BizzBingo.com we´ve integrated the following artifacts for the Nightliybuild:

%system.teamcity.build.checkoutDir%\Main\Source\BusinessBingo\Source\BusinessBingo.Web\bin\BusinessBingo.*.dll => Assemblies
%system.teamcity.build.checkoutDir%\Main\Source\BusinessBingo\Source\BusinessBingo.Web\bin\BusinessBingo.*.pdb => Assemblies
%system.teamcity.build.checkoutDir%\NDependOut\**\* => Reports\NDepend
%system.teamcity.build.checkoutDir%\Main\Docs\HtmlTemplate\**\* => HtmlTemplate.zip

The first and the second are the Dlls/Pdbs - the " =>" shows in which artifact folder it should be copied. For this you could use Wildcards ore, like in line 4, you let the file zip automatically.

Result:

image

The most important one is line 3. Here we took the generated report files from the build step from "NdependOut" Dir and pass them to the artifact path Reports\NDepend.

Integrate NDepend Reports Tab

At least we want the HTML report to be shown in TeamCity. For this you need to configure the following in the server configurations:

 image

image

For every build the report will be searched. If the file is found on the artifacts in the build the Report Tab will be shown either:

 image

That´s it.

TL;DR

Most important steps:

- Create .ndproj files

- Install NDepend on the Buildserver

- The Assemblies, which are in the .ndproj file, should be built somehow or be there as an artifact

- Save the report as an artifact into TeamCity

- Introduce the "NDepend Report" in the server administration to TeamCity

- Take a look on it Smiley

Troy Hunts blogpost was a big help for me with this. The NDepend analyses is based on an other artifact in his example - this would be a bigger challenge for TeamCity functions - but my way should be working as well Zwinkerndes Smiley