C# – How to automatically fail a nant build if NDepend query raises a warning

ccontinuous integrationcruisecontrol.netnantndepend

OK first some background. I am busy automating our build process. We run a mixture of Vs 2005 and VS 2008 both targeting platform 2.0. We use Nant to do our builds using the MSBUILD task to do the compile and Cruise Control .net to do our CI. Currently we treat all warnings as errors, fail the build if any FxCop rules fail (except a small subset that we disabled), fail the build if Simian detects any code duplication of more than 5 lines across all projects.

I have written NDepend CQL query to enforce a few rules that are hard to implement in FxCop. I want to fail the build if the number of lines in a method/class breach a certain limit. I also want to fail if the cyclomatic complexity of a method is too high.

I can easily run NDepend as part of my build. But I can't get the build to fail if my CQL queries return results > 0

So this is the question:

  1. Has anybody tried something
    similar?
  2. Is there a Nant task
    that supports this?
  3. If there is
    a Nant task that calls NDepend, but
    doesn't fail the build is the source
    available so I can add this feature?

Thanks,
Stephen

Best Answer

What we do is actually have a powershell script run right after that parses through the output file, and throws a series of errors with an appropriate message depending on which condition it found. As soon as powershell throws an error the build fails.