From StyleCop’s website:

StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. StyleCop has also been integrated into many third-party development tools.

If you have installed StyleCop, then by default, StyleCop violations only appear as warnings when you do a build. This is fine, unless you want StyleCop violations to fail a build, such as when your team uses a continuous integration build or a gated check-in. In order to cause StyleCop violations to fail your build, you need to add the following element to each of your .csproj files:


You should place this “StyleCopTreatErrorsAsWarnings” element under the Project/PropertyGroup element. In addition to this element, you need to add an import element in order to import the StyleCop MSBuild targets. This will look something like the following:

<Import Project="$(ProgramFiles)\MSBuild\Microsoft\StyleCop\v4.4\Microsoft.StyleCop.targets" />

This “Import” element should be a child of your Project element. You can see that the attribute represents a path to an MSBuild targets file. The path also includes a version number for the particular version of StyleCop I have installed. You may have to adjust the path as necessary.