It seems it is impossible to write a pre-commit hook that uses StyleCop ...

Jul 8, 2013 at 4:39 PM
I have now tried for days to achieve the following and have come to the conclusion that it is just infeasible with StyleCop:

I want a Subversion pre-commit hook that checks added and updated files for StyleCop conformance and rejects commits with non-conforming files.
  • This has to be done in a pre-commit hook, because once the commit succeded and a file violates your coding conventions, its SVN history is already screwed up with useless formatting changes. I don't want that.
  • It must, of course, also be done via the command line. In StyleCop's case that means MSBuild integration.
The problem with this approach is that (if I get it right) the MSBuild StyleCopTask will not work without the ProjectFullPath property set to a .csproj file that includes the file(s) that will get analysed.

First, it is extremely cumbersome to find out to which .csproj file a .cs file that got updated belongs to. You basically have to scan every .csproj file in your repository and check if it references the updated code file.

And then, even if you know the .csproj file, you must go through the hassle of building a temprorary directory tree that matches your repository's structure before the commit, but has the updated files merged in it, so you can build the whole thing.

That's why I'm ultimately giving up. Unless someone shows me a way of using the StyleCopTask without a .csproj file or with a minimal dummy .csproj file, I'm assuming you cannot achieve what I want.

It's a pity, because StyleCop is such a cool tool, but is not suitable for really enforcing a coding style...