Integrate NDepend with TFS

For a serious NDepend and TFS2010 integration, we encourage you to use the Open Source project : NDepend TFS 2010 integration





Integrating NDepend with Team Foundation Server 2008

First create a NDepend project (.xml or .ndproj) or use an existing one. It should be in source control so you can reference it for TFS. Then you have two options:

▲▲ Go to Top ▲▲


    Option 1: Adding a MSBuild target to your solution

    Add a post-build task to an existing project, or create a specific msbuild project for NDepend and add it to the solution to build. The task itself can be either stand-alone :

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Target Name="NDepend"  >
        <PropertyGroup>
          <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath>
          <NDProject>$(SolutionDir)MyProject.ndproj</NDProject>
          <NDOut>$(TargetDir)NDepend</NDOut>
          <NDIn>$(TargetDir)</NDIn>
        </PropertyGroup>
        <Exec
          Command='"$(NDPath)" "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/>
      </Target>
    </Project>

    Where:

    • NDPath: is the path to the NDepend console executable (you need a valid Build Machine license on the server)
    • NDProject: is the path to the NDepend project
    • NDOut: is the path were the reports will be generated
    • NDIn: is the path to binaries to analyze (you can specify several directories by using spaces)

    You can also use the built-in NDepend MSBuild task:

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <NDPath>c:\tools\NDepend\</NDPath>
            <NDProject>$(SolutionDir)MyProject.ndproj</NDProject>
        </PropertyGroup>
      <UsingTask AssemblyFile="$(NDPath)\MSBuild\NDepend.Build.MSBuild.dll" 
             TaskName="NDependTask" />
      <Target Name="NDepend"  >
          <NDependTask NDependConsoleExePath="$(NDPath)"
             ProjectFilePath="$(NDProject)" />
     </Target>
    </Project>


    You can simply add one of these targets to an existing project (csproj or vbproj) and add the content of the project element inside the <TargetName="AfterBuild"></Target> element of the project to build.
    ▲▲ Go to Top ▲▲


    Option 2: Creating a specific build project in TFS 2008

  • 1. Create a new build definition, specifying the Name, Workspace and Project
  • 2. If you’re using the default naming scheme, you should have your build proj file under $/ProjectName/TeamBuildTypes/BuildName
  • 3. Using an XML editor, edit the TFSBuild.proj under the above directory. Just after the last ItemGroup closing tag in the project, add a custom step :

    <Target Name="AfterCompile" >
        <BuildStep         TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
            BuildUri="$(BuildUri)"
            Message="Running NDepend analysis">
            <Output TaskParameter="Id" PropertyName="StepId" />
        </BuildStep>
        <PropertyGroup>
            <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath>
            <NDProject>$(SolutionRoot)\Main\src\MyProject.ndproj</NDProject>
            <NDOut>$(BinariesRoot)\NDepend</NDOut>
            <NDIn>$(BinariesRoot)\Release</NDIn>

        </PropertyGroup>
        <Exec 
          Command='$(NDPath) "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/>
        <BuildStep
            TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
            BuildUri="$(BuildUri)"
            Id="$(StepId)"
            Status="Succeeded" />
        <OnError ExecuteTargets="MarkBuildStepAsFailed" />
    </Target>

    <Target Name="MarkBuildStepAsFailed">
        <BuildStep
            TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
            BuildUri="$(BuildUri)"
            Id="$(StepId)"
            Status="Failed" />
    </Target>


  • 4. Save the file


  • ▲▲ Go to Top ▲▲


    Accessing the report files

    Once TFS has built the build project, the NDepend report will be inside the Drops folder, under the relevant build version.

    ▲▲ Go to Top ▲▲




Integrating NDepend with Team Foundation Server 2010

For a serious NDepend and TFS2010 integration, we encourage you to use the Open Source project : NDepend TFS 2010 integration

Since the TFS build project format has completely changed between TFS 2008 and TFS 2010, the options are slightly different:

▲▲ Go to Top ▲▲