A quick precursor to say that I've done the usual searching around the forums and net in general, and I've tried a multitude of suggestions found on this forum and elsewhere to no avail.

The problem I'm having is that my company is looking to implement internal automated peer-reviews (to an extent of course) with the use of tools such as StyleCop, ReSharper and JSLint (etc etc).

We're using a custom NuGet package against our internal NuGet Package Repository (feed) so that our developers get an administered release of tools (i.e. they cannot download the latest StyleCop when it comes out until its been reviewed and released) with the addition of our custom rules (StyleCop Settings file). Because we want to use StyleCop MSBUILD tasks to highlight errors at build time, the assemblies for StyleCop need to be exact and therefore we're ruling out installations of the C:\Program Files\ version in favour of a NuGet release.

I've managed to create a NuGet package that installs to a project (class library, web site, etc), copies the approved StyleCop assemblies (StyleCop.dll, StyleCop.CSharp.dll and StyleCop.CSharpRules.dll), Settings.StyleCop and StyleCop.Targets to the package folder, and modifies the .csproj file to include the following nodes (this just a snippet of course):

If I have StyleCop installed as C:\Program Files\ and in C:\Program Files\MSBUILD then everything works, but using this method the StyleCop.Targets doesn't seem to work correctly. It is being used as Visual Studio 2010 throws errors if the file is removed and it creates a StyleCop.Cache file. The StyleCop.Targets file has been changed to point at the local DLL in the NuGet package folder, and I have tried a couple of different .Targets files including the standard StyleCop one (with relative filepath changes). Even if I override the MSBUILD properties locally it doesn't work, such as OverrideSettingsFile.

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!

Argh... thanks for the solution! I've tried to use StyleCop from NuGet package "StyleCop" to build my own scenario, but it did nothing. The problem was in missing StyleCop.CSharpRules.dll. Then I switched to "StyleCop.MSBuild" NuGet package, which contains StyleCop.CSharpRules.dll, and now everything works fine!
–
Dmitry LobanovJun 21 '12 at 8:09