Integrate NDepend with AppVeyor
So far we don't propose a first-class integration with AppVeyor but we are planning to do it.
You can vote for AppVeyor integration on our User Voice.
For now, you can follow this awesome in-depth tutorial written by Jimmy Pelletier reproduced below, courtesy of the author.
In this documentation I provide step by step instructions on how to integrate NDepend into your CI pipeline for quality control and historical analytics. For quality control I will demonstrate how to fail your build when violating an NDepend rule and for historical analytics we will publish the NDepend report as a build artifact.
Prerequisites & Assumptions
In order to follow along with the steps provided in this article there are a few prerequisites. You will need:
I have also assumed you know how to work with .NET, Visual Studio and Git.
Making the tools available during the build
In order to run NDepend as part of your build pipeline you will need to make the NDepend.Console.exe available to run during the build. When working with a cloud build agent like AppVeyor, options for installing tools and setting up the environment are limited. We’ll simply be checking NDepend into source control. First download the zip file. Then copy its content into a tools directory. I put mine in ./tools/NDepend. You will also need to put your Build Machine license file in here.
Create an NDepend project
To do anything with NDepend we need to create an NDepend project. The way to get this done is to:
Create your build script
Next we need to add a build script to tell AppVeyor how to build your project. Full details of how AppVeyor build scripts work can be found in the AppVeyor documentation but the one I’ll include here is pretty self explanatory and is correct at the time of writing (September 2018). The file is placed in the root of the repository and is called appveyor.yaml.
The interesting thing to note is that we need to resolve the full absolute path of the NDepend project file to pass in to NDepend. Notice that here our NDepend project file is named SomeProject.ndproj.
image: Visual Studio 2017 before_build: - ps: nuget restore build: project: SomeProject.sln after_build: - ps: $ndproj = Resolve-Path .\SomeProject.ndproj - ps: .tools\NDepend\NDepend.Console.exe $ndproj
Setting up AppVeyor and our first build
Next we need to set up our GitHub repo to build in AppVeyor.
Failing the build
NDepend will now fail on any Quality Gate failure. AppVeyor terminates a build upon a command that returns a non-zero exit code. At least one Quality Gate failing means that NDepend.Console.exe will return a non-zero exit code as explained in Quality Gates and Build Failure.
Thus, the easiest way to test build failure is to modify the “Critical Issues” quality gate. First remove the predicate that restricts this rule to considering only critical issues. Then reduce the failif threshold so it will fail on a single issue. With the default rule set and nearly any solution this should be enough to trip the quality gate. Your Quality Gate CQLinq query should now look like this:
// <QualityGate Name="Critical Issues" Unit="issues" />
Publishing the NDepend report
To publish the NDepend report we need a bunch of files the NDepend writes to ./NDependOut during the build process. AppVeyor allows us to zip these files up and present them for download. Add the following to the end of your appveyor.yaml file:
artifacts: - path: NDependOut name: NDependOut type: zip
Then download the zip file from the “Artifacts” tab on a completed build and extract it to view the html report.
About The Author