开发者

Integrate StyleCop in NAnt buildscript

I开发者_如何转开发s there a way to integrate StyleCop in a NAnt script such that the build fails if there are too many style violations?

There doesn't seem to be a NAnt task for StyleCop, but we've found StyleCopCmd. However this only seems to generate an XML file as output that we'd have to parse. Is there some easier solution?


Yes - I set StyleCop up at work just last week! (I didn't use anything other than StyleCop...)

Basically, all I needed to do, was to get StyleCop working in Visual Studio 2008, making sure that my codebase passed all of it's warnings, and then changed the setting in the .csproj file to make it's findings Errors, instead of Warnings.

Then, when I ran the same NAnt script, the build should pass as before.

But the trick is to go back into your code, violate one of the rules but quit out of VS2008 and then run your build script. The code should fail the StyleCop rule and fail your build.

Hope this helps!


You don't need to do anything with NAnt at all.

You just have to two things once:

  • add two lines to every .csproj file
  • include the StyleCop files in your project and put them into source control

You can find a more detailed description of the process here: http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/24/source-analysis-msbuild-integration.aspx

After that, StyleCop will run on EVERY build, no matter on what machine (and without installing it on each machine) and no matter how the build was started (from Visual Studio, from MSBuild...).

So, as long as NAnt calls MSBuild to actually build the solution, StyleCop will run as well.


In case you don't want to do it thru MSBuild, you can do it using StyleCopCLI http://stylecopcli.sourceforge.net/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜