My bare minimum NDepend rules (and how to get them into a new project)

When you run an Ndepend anylsis over a project you will notice a certain tendency of the Code Queries (CQL) to overwhelm you. By default NDepends comes with a lot of queries against your code that can help you to have an eye on code quality metrics.

After having used NDepend for some like, I like to keep a bare minimum of rules around that I deem really important…





I haven’t seen a simple way to get my own set of CQL queries into an NDepend project, so here’s what I do to get them into a new project.

function ReplaceNode([string]$projectName) {
  $here = pwd
  $xml = New-Object -TypeName System.Xml.XmlDocument
  $oldNode = $xml.SelectSingleNode("/NDepend/CQLQueries")

  $xml2 = New-Object -TypeName System.Xml.XmlDocument
  $xml2.Load("C:\dotnet\bin\NDepend Support\CQL.xml")
  $newNode = $xml2.SelectSingleNode("/CQLQueries")
  $imported = $xml.ImportNode($newNode,$true)

It assumes you are in the directory that contains your new NDepend project, requires you to enter the name and has the location of your CQL queries hard coded.