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:
The binary can be downloaded here: https://github.com/unintelligible/GendarmeMsBuild/downloads
The source code is available here: https://github.com/unintelligible/GendarmeMsBuild
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
Never mind. I just found DefectsCauseFailure=”False”.
Comment by Lex Li — October 3, 2010 @ 2:48 am
@Lex Li: no worries, the naming is perhaps not clear enough…
Comment by Nick — October 3, 2010 @ 12:56 pm
@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
Hi Nick, thanks for the update. Love it.
Comment by Lex Li — October 4, 2010 @ 1:08 am
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
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
@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
Many Thanks for this Integration. I Like it and am looking for it…
Comment by Arun Mariappan K — September 22, 2011 @ 11:48 am
“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
@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