Cannot make StyleCop errors appear as build errors (rather than warnings)

1.9k views Asked by At

I am trying to get builds to fail if they do not pass StyleCop. Currently, these are only being displayed as warnings. I have tried to follow the documentation here.

I have added to my CSProj file <Import Project="$(ProgramFiles)\MSBuild\StyleCop\v4.7\StyleCop.targets" /> which seems to correctly include StyleCop.

Then, I added the StyleCopTreatErrorsAsWarnings set to false in my csproj file. Here is the start of my CSProj file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <Import Project="$(ProgramFiles)\MSBuild\StyleCop\v4.7\StyleCop.Targets" />  
  <PropertyGroup>
    <StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>

This causes, in Bamboo (my continuous integration server) warnings to appear, but no errors. The same occurs in Visual Studio.

Why are StyleCop errors still appearing as warnings?

1

There are 1 answers

0
boxkita On BEST ANSWER

you need to move the stylecop import after the C# import line. Also you need to add the StyleCopEnabled = true property in the csproj file