Unintelligible

Saturday, October 2, 2010

Gendarme MSBuild task

I just wrote a quick MSBuild wrapper around the great Gendarme tool. It allows running Gendarme as part of an MSBuild task/project, and supports all the options that the command-line runner supports.

It also integrates with Visual Studio:

Visual Studio screenshot

The binary can be downloaded here: http://github.com/unintelligible/GendarmeMsBuild/downloads

The source code is available here: http://github.com/unintelligible/GendarmeMsBuild

posted by Nick at 1:14 am - filed in .net  

11 Comments »

  1. I really like this integration, as it also works for SharpDevelop. However, it is inconvenient to have violations listed as Error. It should be by default displayed as Warnings, similar to FxCop. Can you change that?

    Comment by Lex Li — October 3, 2010 @ 2:42 am

  2. Never mind. I just found DefectsCauseFailure=”False”.

    Comment by Lex Li — October 3, 2010 @ 2:48 am

  3. @Lex Li: no worries, the naming is perhaps not clear enough…

    Comment by Nick — October 3, 2010 @ 12:56 pm

  4. @Lex Li: I updated the task as per your feedback (it sounds like a good idea for the task to behave as FxCop does - I hadn’t actually tried running it myself.)

    The task defaults to logging defects as warnings (not errors), and there’s a new WarningsAsErrors property that allows you to switch that.

    Thanks for the comments.

    Comment by Nick — October 3, 2010 @ 2:40 pm

  5. Hi Nick, thanks for the update. Love it.

    Comment by Lex Li — October 4, 2010 @ 1:08 am

  6. Nick, nice work.

    However, It’s not quite working for me without a re-jig of the Execute() method. I’m getting a Process ExitCode of 0, so the CreateVisualStudioOutput() method is not called, even though Gendarme is creating an output XML file correctly in the location I specify. If I comment-out the if (exitCode != 0) then it works fine (although I’m not ruling out other possible side-effects of removing this check :)

    Also, with the output in the Warnings panel in VS, when I double-click an issue, it jumps to the correct file, but not to the correct line within the file even though the line number is present. Is this a limitation of Gendarme’s output?

    Comment by Paul — February 23, 2011 @ 3:54 pm

  7. Actually forget that last paragraph, looks like it doesn’t jump to the correct line number in Visual Studio 2005, in Visual Studio 2008 it works correctly.

    Comment by Paul — February 23, 2011 @ 4:19 pm

  8. @Paul Apologies for the delay in the response, for some reason I wasn’t getting notified of any comments.

    Gendarme doesn’t emit line numbers for all warnings, so some are against a class or even a project rather than against a particular line.

    I’m not sure why you need to comment out the exit code - which version of Gendarme are you using? I haven’t had this experience myself with v2.6 or 2.8, but if you could provide any additional details (in particular, which exit code it’s emitting) I’d be happy to look further into it.

    Comment by Nick — April 4, 2011 @ 8:01 pm

  9. Many Thanks for this Integration. I Like it and am looking for it…

    Comment by Arun Mariappan K — September 22, 2011 @ 11:48 am

  10. “Gendarme can also integrate with Visual Studio, so that Gendarme is run as part of building project. Simply add the following to the bottom of the .csproj file (just before the tag).”

    About this, how can I add programatically ?

    Comment by kiquenet — October 17, 2012 @ 11:24 am

  11. @kiquenet - you need to open up the .csproj file with a text editor, find the tag mentioned, and copy/paste the code snippet into the .csproj file.

    You could parse the .csproj file as XML, and use XML APIs (XDocument or XmlDocument) to add the snippet to the file; this might be helpful if you have a large number of .csproj files you want to add the snippet to?

    Comment by Nick — October 18, 2012 @ 5:37 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment