StyleCop Class

MSBuild Extension Pack

StyleCop Class MSBuild Extension Pack Help 4.0.12.0
Wraps the StyleCopConsole class to provide a mechanism for scanning files for StyleCop compliance.

Valid TaskActions are:

Scan (Required: SourceFiles, SettingsFile Optional: ShowOutput, ForceFullAnalysis, CacheResults, logFile, OutputFileOutput: Succeeded, ViolationCount, FailedFiles)

Remote Execution Support: No

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.CodeQualityStyleCop

Namespace: MSBuild.ExtensionPack.CodeQuality
Assembly: MSBuild.ExtensionPack.StyleCop (in MSBuild.ExtensionPack.StyleCop.dll) Version: 4.0.0.0

The StyleCop type exposes the following members.

Constructors

  NameDescription
Public methodStyleCop
Top
Properties

  NameDescription
Public propertyCacheResults
Sets a value indicating whether StyleCop should write cache files to disk after performing an analysis. Default is false.
Public propertyFailedFiles
Gets the failed files collection
Public propertyForceFullAnalysis
Sets a value indicating whether StyleCop should ignore cached results and perform a clean analysis.
Public propertyLogFile
Sets the log file.
Public propertyOutputFile
Sets the path to the generated output file.
Public propertySettingsFile
Sets the path to the settings file to load.
Public propertyShowOutput
Sets a value indicating whether to ShowOutput. Default is false
Public propertySourceFiles
Sets the source files collection
Public propertySucceeded
Gets whether the scan succeeded.
Public propertyViolationCount
Gets the violation count.
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
    <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
  </PropertyGroup>
  <Import Project="$(TPath)"/>
  <Target Name="Default">
    <!-- Create a collection of files to scan -->
    <CreateItem Include="C:\Demo\**\*.cs">
      <Output TaskParameter="Include" ItemName="StyleCopFiles"/>
    </CreateItem>
    <!-- Run the StyleCop MSBuild task -->
    <MSBuild.ExtensionPack.CodeQuality.StyleCop TaskAction="Scan" SourceFiles="@(StyleCopFiles)" ShowOutput="true" ForceFullAnalysis="true" CacheResults="false" logFile="C:\StyleCopLog.txt" SettingsFile="C:\Program Files (x86)\StyleCop 4.7\Settings.StyleCop">
      <Output TaskParameter="Succeeded" PropertyName="AllPassed"/>
      <Output TaskParameter="ViolationCount" PropertyName="Violations"/>
      <Output TaskParameter="FailedFiles" ItemName="Failures"/>
    </MSBuild.ExtensionPack.CodeQuality.StyleCop>
    <Message Text="Succeeded: $(AllPassed), Violations: $(Violations)" Importance="high"/>
    <!-- FailedFile format is:
        <ItemGroup>
            <FailedFile Include="filename">
                <CheckId>SA Rule Number</CheckId>
                <RuleDescription>Rule Description</RuleDescription>
                <RuleName>Rule Name</RuleName>
                <LineNumber>Line the violation appears on</LineNumber>
                <Message>SA violation message</Message>
            </FailedFile>
        </ItemGroup>-->
    <Message Text="%(Failures.Identity) - Failed on Line %(Failures.LineNumber). %(Failures.CheckId): %(Failures.Message)"/>
  </Target>
</Project>
See Also

Reference