Domanda

According to this blog, you can set all/certain projects to treat StyleCop violations as build errors instead of warnings:

By default, StyleCop violations will show up as build warnings. To turn StyleCop violations into build errors, the flag StyleCopTreatErrorsAsWarnings must be set to false. This flag can be set as an environment variable on the machine, or within the build environment command window. Setting the flag this way will cause StyleCop violations to appear as build errors automatically for all projects where StyleCop build integration is enabled.

Alternately, this flag can be set within the project file for a particular project. Open the .csproj file for your project again, and find the first PropertyGroup section within the file. Add a new tag to set the StyleCopTreatErrorsAsWarnings flag to false.

This doc shows where you can turn on/off individual rules, but it doesn't seem to support setting the severity, only completely turning them on/off.

Is it not possible to have more granular control of which rules result in errors vs. warnings?

È stato utile?

Soluzione

It's not supposed to, but if you really want it.. why not?

Here is an idea, not a complete solution.

There are two useful lines in StyleCop.Targets file. First one imports StyleCop task:

<UsingTask AssemblyFile=".\StyleCop.dll" TaskName="StyleCopTask"/>

and this one calls it:

<StyleCopTask
  ProjectFullPath="$(MSBuildProjectDirectory)"
  SourceFiles="@(StyleCopFiles)"
  AdditionalAddinPaths="@(StyleCopAdditionalAddinPaths)"
  ForceFullAnalysis="$(StyleCopForceFullAnalysis)"
  DefineConstants="$(DefineConstants)"
  TreatErrorsAsWarnings="$(StyleCopTreatErrorsAsWarnings)"
  CacheResults="$(StyleCopCacheResults)"
  OverrideSettingsFile="$(StyleCopOverrideSettingsFile)"
  OutputFile="$(StyleCopOutputFile)"
  MaxViolationCount="$(StyleCopMaxViolationCount)"
        />

So you basically need to call it twice, first one specifying TreatErrorsAsWarnings as false (so that it fails if there are any warnings), and second one with true (resulting in just warning).

Also, you will need to use two separate settings file - first one with stylecop 'errors', second with 'warnings'.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top