Wednesday, June 24, 2009

StyleCop and Legacy Code

Like so many Microsoft tools, they always seem to provide you with about 90% of what you need, and the 10% they don't is very frustrating. When you run the StyleCop install, it will insert a tool in the Visual Studio Tools menu, which you can run at any time.

I installed it today and note these problems:
  • In Visual Studio, the tool ignores what you currently have selected and processes the WHOLE solution. That's ridiculous. Microsoft knew that the first attempt at using this tool would produce thousands of warnings. You would think they would realize that the average person would want to run this on a single file only. Not a solution with 60 projects and hundreds of source files. Sheesh. What I would like is this: If I have a file selected, run the tool on that file. If I have a project selected, run the tool on that project. If I have the solution selected, run the tool on the whole solution. This isn't rocket science.
  • They provide a way to bypass certain projects or files by letting you modify the .csproj file. They even provide a utility to do this for you. But guess what, when you run the tool in Visual Studio it IGNORES these settings. GOOD GRIEF.
  • There is no standalone tool. The tool must be integrated into Visual Studio and/or MSBuild.
  • The only way to selectively run StyleCop and have it honor the project exclusion settings is to do a build. But to do that, you have to integrate the tool into MSBuild. When you do that in a shared environment, everyone has to install and configure StyleCop, even if they don't use it, otherwise they will not be able to build on their machines. Yes, they do provide a hack for team development, but this requires that StyleCop files be checked-in to source countrol along with your source. Ick.

Someone at work suggested that I create a new solution with just the project of interest. The problem is that the project has dependencies on other projects in the solution, using project dependencies, not file dependencies. If I start adding in all the dependent projects, I'm back to my original problem of thousands of warnings for source files that I am not interested in right now.

I did all this at work today. I am not sure that I want to or can continue with it. I may just do an Undo-checkout and throw it all away. In short, it is a good 90% solution, but the last 10% could be a show-stopper. And that's too bad.


  1. To run the tool only on a single file, right click on the file itself, and select Run StyleCop.

  2. Thanks Jason, I also noticed that not 10 min. after I made this post! Which I also commented on in the next one...