HowTo: detect code depending’s with NDepend & TeamCity

 

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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

About the author

Written by Code Inside Team

Learn more about our team.

Comment on this post

Recent Posts

  • Automated Security Analyser for ASP.NET websites

    Evil Hackers are lurking everywhere and many Web-applications are delicately and share “too much” with the attacker. A quick (first!) overview offers the Tool “ASafaWeb”. All the website does is making a few requests and writing an Analyses including problem solving’s. There are no permanent disadvantages (bad requests/ DoS attacks and so on). Example: KnowYourStack.com ...

  • image1489-570x194.png
    „Sign in with Twitter“ for your own ASP.NET WebApp

      “Sign in with Twitter” is a popular practice to authenticate the users on your website. One advantage compared to an own registration is the lower inhibition for the user. But on the other hand Twitter doesn’t fess up with all the information’s and you will get into a kind of addiction. At the end ...

  • image1485-570x194_thumb.png
    CodePlex is going to be updated

      CodePlex the Microsoft Open Source Project Hosting Plattform hasn’t changed that much in the last few years and for a few times I thought Microsoft stopped the whole developing process. But now I found out that there is still life in the project. Maybe it is because of the success of GitHub or because ...

  • image1474_thumb.png
    What does Adobe in the flash-free web? Magazine-Style Layouts with CSS Regions!

      Adobe is well known for Photoshop and Flash but of course there is a lot more. According to the “Future Post” from Google Adobe declared one of their big subjects on a Blogpost. I’m talking about the W3C Working Draft to CSS Regions. Adobe cooperates with the WebKit Team and W3C on this. What ...

  • image1471-523x194.png
    HTML 5 Games, Tooling & 3D

      Game Developing is an interesting subject for all kind of software developer. But as a web developer without any Flash-skills there aren’t that much starting points. With HTML5 and the combination between Javascript, CSS3 and fast browsers there are the first “robust” HTML5 games. HTML5 games? Is this real? Neowin created a “Top 10” ...

Support us