Implementing StyleCop MSBUILD From NuGet Package

I'm posting the solution I came across for anyone in a similar position.

Firstly I followed this excellent guide on debugging MSBuild operations, which helped me to iron out some of the logic and variables:

http://blogs.msdn.com/b/visualstudio/archive/2010/07/06/debugging-msbuild-script-with-visual-studio.aspx

Following this I checked the StyleCopViolations.xml which was in my /obj/Debug/ folder. This however always returned 0 results, with just the following XML:

<StyleCopViolations/>

I did some research on this and found that I needed to include StyleCop.CSharpRules.dll in to my NuGet/lib/net40/ folder with the StyleCop.dll, StyleCop.CSharp.dll and StyleCop.Settings files.

My project didn't needed references to any of the aforementioned assemblies, but I realised that my NuGet package had a dependency on the StyleCop NuGet package which did not include StyleCop.CSharpRules.dll.

After adding this assembly I was still seeing 0 results, so I did a manual override of all 3 assemblies and the .Settings file from a fresh install of the StyleCop C:\Program Files\StyleCop\ installer (from CodePlex). After overwriting the NuGet package assemblies this started working!

So to wrap up, debug your MSBuild (with the link at the top of this post) and don't use the NuGet package just yet!

Cheers


Use StyleCop.MSBuild instead of StyleCop as suggested by Dmitry Lobanov.

i.e use the command install-package stylecop.msbuild in the package manager console.