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

1

6

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?

Heigho answered 14/11, 2014 at 22:8 Comment(1)
Is it possible that the $(StyleCopTreatErrorsAsWarnings) is being overridden on the MSBuild command line? If you can run your build with diagnostics on it would allow you to check this.Gabie
A
1

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

Alesandrini answered 18/11, 2014 at 0:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.