This project is read-only.

StyleCop - enforcing style convention with backward compatibility

Jun 1, 2012 at 10:09 AM


I'm having a problems with recent StyleCop updates. And serious ones. They break my old code on older projects. So I was wondering how you cope with those issues.

For instance, I have one framework project that I use on many projects. And I reference it in my solutions from SVN using externals. It was validated with StyleCop versions and below. And all was working fine for a long time. I am using StyleCop in a way that it reports style violations as errors, so that it forces developers to fix them before code could be compiled.

But since StyleCop (and next releases) came out my problems started. If I updated to those versions, I couldn't no longer compile my old projects (which are now in production). So the only solution is to again fix the code for StyleCop (possible branching framework project or something).

The other solution is to never update on newer version but that is also just a short term fix.

Do you also have problems like these?

Jun 1, 2012 at 10:13 AM
Edited Jun 1, 2012 at 10:14 AM

Yes - StyleCop source itself needed fixing. You have a few options. 

1. Never upgrade again - not a good idea and many fixes are included in new versions.

2. Exclude the source you are already happy with and and not changing from StyleCop analysis - using a StyleCop settings file.

3. Exclude the individual files by adding an ExcludeFromStyleCop entry for the compile item in the csproj.

4. Set your maxViolation count == to the number of issues you have now. As you gradually fix them reduce the StyleCop max violation count back to zero.

5. Fix all the StyleCop issues.


Some more info here :

Jun 1, 2012 at 1:25 PM
Edited Jun 1, 2012 at 2:19 PM


thanks for listing all of my options.

So I have a new question. As I said, my Framework project is used in many solutions as svn-externals, and on legacy projects I can't change source for it or possibly upgrade to new version of framework without testing.

What I was thinking, is there any way that I can exclude those projects/files from StyleCop validation but on a solution level.

For example, on Solution1 I say you don't validate Framework project, but Framework project in Framework solution is checked as it is now.

I'm not sure that you can do that, since StyleCop is project based, not a solution based, am I right? I can't put FileList in solution's root Settings.StyleCop file which would contain list of files in Framework project that would be excluded from validation.

Thanks for your help!

Best regards!