To be able to run NDepend analysis during a build on a TeamCity server you need to install NDepend on the server which hosts the TeamCity agent that will run the NDepend analysis.
Just unzip NDepend in a folder that the TeamCity agent can use.
In our example we will use “C:\Program Files\_Tools\Development\ndepend”.
First step is to configure TeamCity to display NDepend analysis as a tab on the
result page of a build.

To do that you need to add a new Report Tab in TeamCity.
Navigate to the Administration menu, then Server Configuration and
finally click on the tab Report Tabs. Click on Create new report tab
and fill up the dialog as on the following screenshot:

Click Save. You should see your new created tab in the table listing all system-wide
report tabs.
Please refer to TeamCity Including Third-Party Reports in the Build Results documentation
for the full help on this.
Now that TeamCity is set to recognize the NDepend report tab we need to configure
the artifact path of NDepend
Choose the build to which you want to add NDepend analysis and click Edit Configuration Settings
and in the section Artifact paths add the string “Tests/Output/NDependOut/**/*=>NDepend”, without the quotes, as on the following screenshot:

Please refer to TeamCity Build Artifact documentation for the full help on this.
Now your chosen TeamCity build is ready to display the result of an NDepend analysis under an NDepend report tab.Artifacts are files produced by a build. After finishing a build, TeamCity searches for artifacts in the build's checkout directory according to the specified artifact patterns. Matching files are then uploaded to the server, where they become available for download.
So we still need to produce the files which will be displayed under the report tab.
To generate the NDepend analysis we will use the provided NDependMSBuild task called NDependTask.
The NDependTaskMSBuild task is stored in the assembly NDepend.Build.MSBuild.dll which is in the folder BuildProcessResources\MSBuild under the folder in which you installed NDepend, e.g. “C:\Program Files\_Tools\Development\ndepend”.
As an example I will use the following solution:
In which you can see:
- A Visual Studio 2008 Web Deployment Projects; TechHeadBrothers.Portal.csproj_deploy, which we will customize to carry out the NDepend analysis build tasks. This is just a MSBuild script, you might use whatever MSBuild file which suits best your need
- The configuration file for NDepend: TechHeadBrothers.Portal.NDependProject.ndproj
In your MSBuild, first import the NDependMSBuild tasks like this:
<UsingTask
AssemblyFile="$(NDependPath)\BuildProcessResources\MSBuild\NDepend.Build.MSBuild.dll"
TaskName="NDependTask" />
|
Then under the <PropertyGroup> tag define the following general path properties:
<SolutionFolder>$(MSBuildProjectDirectory)\..\..</SolutionFolder>
<TestsFolder>$(MSBuildProjectDirectory)\..\..\Tests</TestsFolder>
|
And the properties for NDepend:
<!-- NDepend -->
<NDependPath>C:\Program Files\_Tools\Development\ndepend</NDependPath>
<NDependProjectFilePath>$(TestsFolder)\NDepend\TechHeadBrothers.Portal.NDependProject.ndproj
</NDependProjectFilePath>
<NDependInDirs>"$(SolutionFolder)\Sources\TechHeadBrothers.Portal\bin";
"C:\Windows\Microsoft.NET\Framework\v2.0.50727";
"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0";
"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5";
</NDependInDirs>
<NDpendOutputDir>$(TestsFolder)\Output\NDependOut</NDpendOutputDir>
|
In your MSBuild, first import the NDependMSBuild tasks like this:
<Target Name="NDepend">
<Message Text="#--------- Executing NDepend ---------#" />
<NDependTaskNDependConsoleExePath="$(NDependPath)"
ProjectFilePath="$(NDependProjectFilePath)"
InDirsDotComaSeparated="$(NDependInDirs)"
OutDir="$(NDpendOutputDir)" />
</Target>
|
And finally we have to call the NDepend target,
<Target Name="AfterBuild">
<CallTarget Condition=" '$(Configuration)' == 'Nightly' " Targets="NDepend" ContinueOnError="false" />
|
If everything is configured correctly, you should see the following result:
