FxCop Class

MSBuild Extension Pack

FxCop Class MSBuild Extension Pack Help 4.0.12.0
The FxCop task provides a basic wrapper over FxCopCmd.exe. See http://msdn.microsoft.com/en-gb/library/bb429449(VS.80).aspx for more details.

Valid TaskActions are:

Analyse (Required: Project and / or Files, OutputFile Optional: DependencyDirectories, Imports, Rules, ShowSummary, UpdateProject, Verbose, UpdateProject, LogToConsole, Types, FxCopPath, ReportXsl, OutputFile, ConsoleXsl, Project, SearchGac, IgnoreInvalidTargets, Quiet, ForceOutput, AspNetOnly, IgnoreGeneratedCode, OverrideRuleVisibilities, FailOnMissingRules, SuccessFile, Dictionary, Ruleset, RulesetDirectory, References, AssemblyCompareMode Output: AnalysisFailed, OutputText, ExitCode)

Remote Execution Support: NA

Inheritance Hierarchy

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

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

The FxCop type exposes the following members.

Constructors

  NameDescription
Public methodFxCop
Top
Properties

  NameDescription
Public propertyAnalysisFailed
Gets AnalysisFailed. True if FxCop logged Code Analysis errors to the Output file.
Public propertyAspNetOnly
Set to true to analyze only ASP.NET-generated binaries and honor global suppressions in App_Code.dll for all assemblies under analysis. Default is false
Public propertyAssemblyCompareMode
Set the assembly comparison mode. Supports None, StrongName, StrongNameIgnoringVersion. Default is StrongName.
Public propertyConsoleXsl
Sets the ConsoleXsl (/consoleXsl option)
Public propertyDependencyDirectories
Sets the DependencyDirectories :(/directory option)
Public propertyDictionary
Sets the custom dictionary used by spelling rules.Default is no custom dictionary
Public propertyExitCode
The exit code returned from FxCop
Public propertyFailOnMissingRules
Set to true to treat missing rules or rule sets as an error and halt execution. Default is false
Public propertyFiles
Sets the Item Collection of assemblies to analyse (/file option)
Public propertyForceOutput
Set to true to write output XML and project files even in the case where no violations occurred. Default is false
Public propertyFxCopPath
Sets the path to FxCopCmd.exe. Default is [Program Files]\Microsoft FxCop 1.36\FxCopCmd.exe
Public propertyIgnoreGeneratedCode
Set to true to suppress analysis results against generated code. Default is false
Public propertyIgnoreInvalidTargets
Set to true to silently ignore invalid target files. Default is false
Public propertyImports
Sets the name of an analysis report or project file to import (/import option)
Public propertyLogToConsole
Set to true to direct analysis output to the console (/console option). Default is true
Public propertyOutputFile
Set the name of the file for the analysis report
Public propertyOutputText
Gets the OutputText emitted during analysis
Public propertyOverrideRuleVisibilities
Set to true to run all overridable rules against all targets. Default is false
Public propertyProject
Set the name of the .fxcop project to use
Public propertyQuiet
Set to true to suppress all console output other than the reporting implied by /console or /consolexsl. Default is false
Public propertyReferences
Sets the Item Collection of assemblies to reference (/reference option)
Public propertyReportXsl
Sets the ReportXsl (/outXsl: option)
Public propertyRules
Sets the location of rule libraries to load (/rule option). Prefix the Rules path with ! to treat warnings as errors
Public propertyRuleset
Specifies the Rule set to be used for the analysis. It can be a file path to the rule set file or the file name of a built-in rule set. '+' enables all rules in the rule set; '-' disables all rules in the rule set; '=' sets rules to match the rule set and disables all rules that are not enabled in the rule set
Public propertyRulesetDirectory
Specifies the directory to search for rule set files that are specified by the Ruleset switch or are included by one of the specified rule sets.
Public propertySearchGac
Set to true to search the GAC for missing assembly references (/gac option). Default is false
Public propertyShowSummary
Set to true to display a summary (/summary option). Default is true
Public propertySuccessFile
Set to true to create .lastcodeanalysissucceeded file in output report directory if no build-breaking messages occur during analysis. Default is false
Public propertyTimeout
Set the override timeout for analysis deadlock detection. Analysis will be aborted when analysis of a single item by a single rule exceeds the specified amount of time. Default is 0 to disable deadlock detection.
Public propertyTypes
Specifies the types to analyze
Public propertyUpdateProject
Saves the results of the analysis in the project file. This option is ignored if the /project option is not specified (/update option)
Public propertyVerbose
Set to true to output verbose information during analysis (/verbose option)
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)"/>
  <ItemGroup>
    <!--- Need to add to the dependencies because MSBuild.ExtensionPack.CodeQuality.StyleCop.dll references StyleCop -->
    <DependencyDirectories Include="c:\Program Files (x86)\MSBuild\Microsoft\StyleCop\v4.4"/>
    <!-- Define a bespoke set of rules to run. Prefix the Rules path with ! to treat warnings as errors -->
    <Rules Include="C:\Program Files (x86)\Microsoft Fxcop 10.0\Rules\DesignRules.dll"/>
    <Files Include="C:\Projects\MSBuildExtensionPack\Releases\4.0.1.0\Main\BuildBinaries\MSBuild.ExtensionPack.StyleCop.dll"/>
  </ItemGroup>
  <Target Name="Default">
    <!-- Call the task using a collection of files and all default rules -->
    <MSBuild.ExtensionPack.CodeQuality.FxCop TaskAction="Analyse" Files="@(Files)" OutputFile="c:\fxcoplog1.txt">
      <Output TaskParameter="AnalysisFailed" PropertyName="Result"/>
    </MSBuild.ExtensionPack.CodeQuality.FxCop>
    <Message Text="CA1 Failed: $(Result)"/>
    <!-- Call the task using a project file -->
    <MSBuild.ExtensionPack.CodeQuality.FxCop TaskAction="Analyse" Files="@(Files)" Project="C:\Projects\MSBuildExtensionPack\Releases\4.0.1.0\Main\Framework\XmlSamples\FXCop.FxCop" DependencyDirectories="@(DependencyDirectories)" OutputFile="c:\fxcoplog2.txt">
      <Output TaskParameter="AnalysisFailed" PropertyName="Result"/>
    </MSBuild.ExtensionPack.CodeQuality.FxCop>
    <Message Text="CA2 Failed: $(Result)"/>
    <!-- Call the task using a collection of files and bespoke rules. We can access the exact failure message using OutputText -->
    <MSBuild.ExtensionPack.CodeQuality.FxCop TaskAction="Analyse" Rules="@(Rules)" Files="@(Files)"  OutputFile="c:\fxcoplog3.txt" LogToConsole="true">
      <Output TaskParameter="AnalysisFailed" PropertyName="Result"/>
      <Output TaskParameter="OutputText" PropertyName="Text"/>
    </MSBuild.ExtensionPack.CodeQuality.FxCop>
    <Message Text="CA3 Failed: $(Result)"/>
    <Message Text="Failure Text: $(Text)" Condition="$(Result) == 'true'"/>
  </Target>
</Project>
See Also

Reference