-
Notifications
You must be signed in to change notification settings - Fork 30
Getting started with the fxcop activity
The FXCop activity allows you to run the FXCop tools directly. This is as opposed to enabling Code Analysis in your Visual Studio project which runs a version of FXCop behind the scenes as part of the build process. The reason you might choose to use the stand alone version of FXCop is because of it richer set of command line parameters to control what is being checked and how. You can also use this activity to run the command line FxCop tool shipped with Visual Studio without going via a Visual Studio project’s settings.
NOTE: In most cases it is expect you will find it easier to run FXCop via the code analysis setting within a project, thus removing the need to edit your workflow to include this activity.
In this example we aim to show that the basic steps that are required to get the activity integrated into a build.
Before you can make use of any of the TFS community build activities you have to make sure they are available for the build system and on your development PC. Instructions for this process can be found in the ALM Rangers build guide or in the getting started page of this wiki. This page assumes the AssemblyInfo activity is available in the developers build process workflow toolbox.
FXCop does an analysis against compiled assemblies, this means calling the FXCop activity needs to be placed after the compile activities
To add this block of activities
- Add the following variable with a scope of the “Compile and Test for Configuration” sequence FXCopResults of type boolean
- Add a FindMatchingFile activity, set the Result to FXCopFiles and the MatchPattern to string.Format("{0}***.dll", BinariesDirectory ). This will recursively find all the .DLL files in the project and add them to the collection.
- Add a FXCop activity with the following properties (these are a minimum to get it working))
- AnalysisFailed – set to the variable FXcopResult
- Files – set to the list of files FileToAnalyse
- FxCopyPath – If you installed the stand alone version of FXCop you can usually leave this property unset as the default is correct. In my case I set to the path for the version of FXCop installed as part of VS2010
- OutputFile – the results file, this is empty if there are no issues with the code. String.Format("{0}\FXCop.xml",DropLocation)
- Add a WriteBuildMessage activity, set the importance to High (so we always see the message) and the Message to String.Format("FXCop analysis failed - returned {0}",FXCopResult). Note that you use this return code, or further processing of the output file to branch within the build process.
As a minimum only the Project and/or Files and OutputFile properties need to be set.
The other properties you could set are:
Property | Direction/Type | Comment |
---|---|---|
Files | InArgument<IEnumerable> | Item Collection of assemblies to analyse |
DependencyDirectoriesary | InArgument<IEnumerable> | Specifies additional directories to search for assembly dependencies. |
Imports | InArgument<IEnumerable> | Name of an analysis report or project file to import |
Rules | InArgument<IEnumerable> | Location of rule libraries to load (/rule option). Prefix the Rules path with ! to treat warnings as errors |
LogResultsToBuildLog | InArgument | Set to true to log the results to the build file. Default is false |
ShowSummary | InArgument | Set to true to display a summary (/summary option). Default is true |
SearchGac | InArgument | Set to true to search the GAC for missing assembly references (/gac option). Default is false |
SuccessFile | InArgument | Set to true to create .lastcodeanalysissucceeded file in output report directory if no build-breaking messages occur during analysis. Default is false |
OverrideRuleVisibilities | InArgument | Set to true to run all overridable rules against all targets. Default is false |
Timeout | InArgument | 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 |
FailOnMissingRules | InArgument | Set to true to treat missing rules or rule sets as an error and halt execution. Default is false |
IgnoreGeneratedCode | InArgument | Set to true to suppress analysis results against generated code. Default is false |
AspNetOnly | InArgument | 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 |
IgnoreInvalidTargets | InArgument | Set to true to silently ignore invalid target files. Default is false |
Quiet | InArgument | Set to true to suppress all console output other than the reporting implied by /console or /consolexsl. Default is false |
ForceOutput | InArgument | Set to true to write output XML and project files even in the case where no violations occurred. Default is false |
Verbose | InArgument | Set to true to output verbose information during analysis (/verbose option) |
UpdateProject | InArgument | Saves the results of the analysis in the project file. This option is ignored if the /project option is not specified (/update option) |
LogToConsole | InArgument | Set to true to direct analysis output to the console (/console option). Default is true |
Types | InArgument | Specifies the types to analyze |
RulesetDirectory | InArgument | 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. |
Ruleset | InArgument | 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 |
FxCopPath | InArgument | Sets the path to FxCopCmd.exe. Default is [Program Files]\Microsoft FxCop 1.36\FxCopCmd.exe |
ReportXsl | InArgument | Sets the ReportXsl (/outXsl: option) |
OutputFile | InArgument | REQUIRED Set the name of the file for the analysis report |
ConsoleXsl | InArgument | Sets the ConsoleXsl (/consoleXsl option) |
Dictionary | InArgument | Sets the custom dictionary used by spelling rules.Default is no custom dictionary |
Project | InArgument | Set the name of the .fxcop project to use |
AnalysisFailed | OutArgument | Gets AnalysisFailed. True if FxCop logged Code Analysis errors to the Output file. |
ExitCode | OutArgument | The exit code returned from FxCop |
OutputText | OutArgument | Gets the OutputText emitted during analysis |
When the build is run you should see an entry in the log
and the FXCop output file will be in the drops location