Jake
Jake

Reputation: 3471

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

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?

Upvotes: 6

Views: 2026

Answers (1)

boxkita
boxkita

Reputation: 36

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

Upvotes: 1

Related Questions