Activate StyleCop only on changed files / Adopting style rules in existing project

Jan 15, 2013 at 10:04 AM


I'd like to use StyleCop on save or change of a file, or only on files that where changed after a certain date.

My Use Case is: I have a rather big project, that does not conform to style rules. Activation of StyleCop will create an (nearly) endless amount of warnings. To much to handle by the development team ad-hoc.

So I'd like to use it only on files that are touched after the Activation of StyleCop, i.e. as soon as a developer changes the file, he has to change the whole file, but will not receives error or warning based on other files.

Is there any way to do this? I.e. by adding StyleCop or StyleCop rules to the Save Hook in VisualStudio?


Any ideas on how to handle adopting style rules in existing projects, would be highly appreciated.

Jan 18, 2013 at 7:45 AM

I think it would be better not to do this in Visual Studio. IMO, the better solution would be to use StyleCop in a pre-commit hook (or whatever concept your version control software offers for that purpose) that checks all files that get commited (and rejects the non-conforming).


Unfortunately, you'll have to write your CLI version of StyleCop yourself unless you want to use MSBuild integration. The latter has the drawback that everybody who wants to commit will have to wait until your projects/solution is built on the server. There might be a workaround for this issue, but I'm not sure since I have not read the entire thread that discusses StyleCop CLI support.



Jan 22, 2013 at 8:38 AM

Thanks for the Answer.


I found the Make Exceptions for all Files Solution from the StyleCop Blog.

I am writing a prototype for an AddIn that will delete the Exceptions for a file if that file is saved. There are some minor problems (like the VisualStudio has to reload the Project if that happens), but it's a fast solution with minimum impact.

The OnCommit/MSBuild solution sound nice though, and more easily manageable in the future.