Domanda

Am trying to configure the static code analysis(FxCop) in my Continuous integration system.But my developers are using a rule set file for static analysis with Visual Studio.

Is there a way that i can re-use the same rule-set file and convert it into a FxCop rule-set dll and perform the static code analysis while build?

Thanks in advance, Ravi

È stato utile?

Soluzione

If you have Visual Studio installed on the CI server, then simply specifying /p:RunCodeAnalysis=[True|False|Always|Default|Never] on the MsBuild command line should run Code Analysis as it was configured on the developer's configuration. The rules files are automatically included in the Visual Studio project file, so they should resolve on their own.

To run FxCop after the build you can specify the ruleset as a commandline parameter:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop>fxcopcmd /?
Microsoft (R) FxCop Command-Line Tool, Version 12.0 (12.0.21005.1) X86
Copyright (C) Microsoft Corporation, All Rights Reserved.

/ruleset:<<+|-|=>file>  [Short form: /rs:<<+|-|=>file>]
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.

/rulesetdirectory:<directory>  [Short form: /rsd:<directory>]
Directory to search for rule set files that are specified by the /ruleset
switch or are included by one of the specified rule sets.

The difficult part of running FxCop from the commandline is that you will want to pass all references and that it can only process files targeting the same .NET system libraries (it can only hold one of those in memory). You can specify these references using the following parameters:

/platform:<directory>  [Short form: /plat:<directory>]
Location of platform assemblies.

/directory:<directory>  [Short form: /d:<directory>]
Location to search for assembly dependencies.

/reference:<file>  [Short form: /ref:<file>]
Reference assemblies required for analysis.

Altri suggerimenti

If you want to run code analysis only without having to call fxcop directly and specify all that extra information, do the following:

<MSBuild Projects="@(CodeAnalysisProjects)" Properties="RunCodeAnalysis=True;Configuration=Release;BuildProjectReferences=False;WarningsAsErrors=False;RunCodeAnalysisDependsOn=;" Targets="RunCodeAnalysis" StopOnFirstFailure="false" />

You send in the list of projects in the itemgroup CodeAnalysisProjects. You run the target RunCodeAnalysis and you set the property RunCodeAnalysis=True. You also set the property RunCodeAnalysisDependsOn=; so that nothing else runs besides code analysis.

This is the same solution we use for our CI. We build all day and then run code analysis only at night.

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