In my post Code Metrics and Code Metrics Tools, I discussed several tools that could analyze your source code and generate a report that could possibly be integrated into an automated build cycle. In this post, I’ll talk about how I integrated one of those tools, NDepend, into a CruiseControl.NET / NAnt Continuous Integration build.
1. Define an input file to tell NDepend what to analyze.
The directory definition can be set to a local project path if needed, as we will worry about making it relative to the build working directory in a later step.
2. Create a target in your NAnt build script to run the NDepend executable.
This target will need to:
a. Copy the input file to the directory you want your output to end up. NDepend will generate output xml files in the same directory as the input xml file.
b. Change the directory information in the input file so that it points to the proper bin directory relative to the build working directory.
c. Call the executable.
3. Copy the xsl report stylesheets into the ccnet\webdashboard\xsl directory.
If you want the images to display, you’ll also want to see my post on Integrating Images Into Custom CruiseControl.NET Build Reports.
4. Add the xsl report plugin entries to the dashboard.config.
I discovered from the CCNet Community Contributions Wiki page for xsl transforms, that Freek Felling had already created some NDepend report xsl’s for use in a CCNet build.
As I’d mentioned before, I liked that NDepend generated a lot of bang for the buck, but the amount of info it provides is almost too overwhelming, so I decided to break this report up so that I could pick and choose which pieces I might want to include in my build. I did this by separating out each section of the ndependreport-ccnet.xsl into it’s own xsl, which you can download as you like from here:
ndependreport-ccnet.xsl (modified from CCNet Contrib version to include image support)
ndependsummary-ccnet.xsl (same as CCNet Contrib)
ndependreport-ccnet-ApplicationMetrics.xsl
ndependreport-ccnet-AssembliesMetrics.xsl
ndependreport-ccnet-AssembliesDependencies.xsl
ndependreport-ccnet-InfoWarnings.xsl
ndependreport-ccnet-TypesMetrics.xsl
ndependreport-ccnet-TypesDependencies.xsl
Here’s an example with all the plugins listed, but you should be able to filter these down to just the ones you care about:
5. Add the output files to merge into your project’s entry in ccnet.config.
Same thing applies here. You should be able to include only the ones necessary for the reports you choose to use.
Final Result:

In the next episode of this series, I’ll talk about the steps required to integrate vil into your CI builds. Keep watching. Don’t touch that dial.