Wednesday, May 28, 2008

Hudson adds support for StyleCop

Last week Microsoft released StyleCop (aka Microsoft Source Analysis for C#), a tool that analyzes C# code and enforces a certain code style (similar to Checkstyle). The tool will go through all C# source files and mark the code style violations. Now Hudson (a Continuous Integration server) together with the Violations plugin has added support for parsing the StyleCop XML report and display the results for every build.

The Violations plugin displays a trend graph over builds so it is real easy to see that your project is progressing in the right direction (decreasing the number of violations). As you can see the plugin also supports FxCop reports.


Each build will display a listing of the files that are violating the code style, and it is also possible to see the number of fixed (or introduced) violations for every build.


Clicking on a file will display excerpts from the C# code showing the violations.


Setup
Follow the guideline here after downloading StyleCop. Add the <Import Project="$(ProgramFiles)\MSBuild\Microsoft\SourceAnalysis\v4.2\Microsoft.SourceAnalysis.targets" /> to every csproj file that you are building within Hudson. When the VS project is built, StyleCop will store a file named StyleCopViolations.xml [Update, if you are using StyleCop 4.2 enter SourceAnalysisViolations.xml in the project folder. As of now, there is no way to store it elsewhere. The XML file contains all violations that were found in the Visual Studio project.

Hudson Configuration
To configure the violations plugin, enable the "Report violations" check box. If there are several VS projects in the build, you should use **/*/SourceAnalysisViolations.xml as it will find XML files in all sub folders.


After configuration, start a new build to analyze and display the StyleCop results in Hudson. To see a trend graph you need at least two successful builds.

Tips
  • Do not enable all rules, choose those that are valid for your organization and make sense for you.
  • Do not activate too many rules at first, as it probably will generate too many violations. Too many violations may be ignored by your co-workers, as it seems to be too much work to fix them all. When the most critical code style violations has been fixed, increase the number of rules.

21 comments:

cody said...

Installed plugin and stylecop Added assembly lines to project files.

Verified Hudson Violations V7.1 plugin and Stylecop 4.3 installed correctly.

Violations plugin reports "No reports" after build.

Checked for presence of XML file, should be **/*/SourceAnalysisViolations.xml
according to above link. Actual name of file generated by Stylecop was
stylecopViolations.xml

Any Suggestion?

redsolo said...

@cody
The directory search is case sensitive, so a work around is to enter "**/StyleCopViolations.xml" instead. For more info see https://hudson.dev.java.net/issues/show_bug.cgi?id=2378.

Anonymous said...

How can I disable StyleCop rules? I cannot find some good documentation of StyleCop...

thx martin

Oliver said...

I can't get StyleCop and the violations plugin to work properly.

I'm using StyleCopCmd to output my StyleCop XML report.

I've filed the following bugs relating to my issues:

https://hudson.dev.java.net/issues/show_bug.cgi?id=3529
https://hudson.dev.java.net/issues/show_bug.cgi?id=3589

I was wondering if you had ever had these problems or if you had any suggestions.

Thanks

Anonymous said...

Using StyleCop 4.3.2.1 and Hudson 1.346, I used the following in my .csproj files to get StyleCop violations and source code linked:


<!-- Causes problems with FxCop and StyleCop violations mixing in some Hudson/StyleCop/MSBuildExtensions version combinations. -->

<PropertyGroup>
<StyleCopOutputFile Condition=" '$(StyleCopOutputFile)' == '' ">StyleCopViolations.xml</StyleCopOutputFile> <!-- two sinqle quotes after the == -->
</PropertyGroup>
<!-- -->
<Import Project="$(ProgramFiles)\MSBuild\Microsoft\StyleCop\v4.3\Microsoft.SourceAnalysis.Targets" />

redsolo said...

@anonymous

Could you open an issue on the Hudson issue tracker? Preferably with an xml showing the problem.

buy Cialis said...

this is perfect because C+ has no change in a long time, maybe with this I can analyze some mistakes in the program code, you know to obtain a better performance.

Penis Enlargement Pills said...

Really you have done great job,There are may person searching about that now they will find enough resources by your post.I like this blog..

Generic Viagra Blog said...

It is a great tool, C+ can sometimes, specially if you are tired, very tricky, and you could miss a letter.

tablet pc 10 pulgadas said...

Gosh, there's a lot of helpful information above!

seositeden.blogspot.com said...

A great deal of useful information for me!

www.almeria-3d.com said...

Quite worthwhile information, thanks for your post.

hcg said...

I have been looking for sites like this for a long time. Thank you!

Cheap SSL said...

This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. - Wildcard SSL

Donanyna said...

The plugin is very useful

saim said...

This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.



natural minerals
best naturals
buy curcumin

free flash intros said...

Saying thanks will not just be enough, for the extraordinary lucidity in your writing. I will immediately grab your rss feed to stay privy of any updates

Cheap SSL Certificate said...

It's really informative resource and also you have comprehensive knowledge of blogging. You truly deserve the right skill of blog writing. Thank you so much for sharing it!


Cheap WildCard SSL | Cheap EV SSL Certificate

Taruhan Bola said...

Hrmm that was weird, my comment got eaten. Anyway I wanted to say that it's nice to know that someone else also mentioned this as I had trouble finding the same info elsewhere. This was the first place that told me the answer. Thanks. 338A Sbobet Casino Ibcbet.com

Judi Bola said...

Great post! I?m just starting out in community management/marketing media and trying to learn how to do it well - resources like this article are incredibly helpful. As our company is based in the US, it?s all a bit new to us. The example above is something that I worry about as well, how to show your own genuine enthusiasm and share the fact that your product is useful in that case. Prediksi Bola Agen Bola Prediksi Bola

Agen Bola Online said...

I have not much time to visit many websites. But today I found this site accidently. I explored much information which is useful to my life. Thanks! Agen Sbobet