Enterprise Developer enables you to perform code analysis using the MSBuild utility when a project has finished building. The MSBuild command line takes a number of switches and parameters that enable you to tailor its behavior.
There are two ways you can configure and run code analysis from the command line:
For example, running MSBuild with /p:RunMicroFocusCodeAnalysisAfterBuild=true specifies that code analysis is to be executed after the build regardless of whether code analysis is enabled in the project's properties.
Running MSBuild with /p:ActiveRulesets="Coding Standards" specifies the rules from the Coding Standards rule sets enabled in the IDE are to be used.
Using these command line parameters, you can create and execute code analysis jobs at the command line without having to change the way your projects are built using the IDE.
To build a project and perform code analysis using MSBuild from the command line:
msbuild [path]MyProject.cblproj [Code-analysis-parameters]
If you specified any parameters for executing code analysis, MSBuild runs code analysis after the build completes. The output from code analysis is displayed in the command line window after the messages from the build.
To perform code analysis from the command line, you run the MSBuild command and specify parameters for code analysis:
msbuild [path]MyProject.cblproj [Code-analysis-parameters]
If no Code-analysis-parameters are specified, MSBuild uses the code analysis settings specified in the IDE and in the project's properties.
MSBuild supports various switches and parameters at the command line. The switch to use for code analysis is /p and you can use the following syntax to specify various properties with it:
msbuild [path]MyProject.cblproj /p:property1=value1;property2=value2;...
Or:
msbuild [path]MyProject.cblproj /p:property1=value1 /p:property2=value2...
For example:
msbuild Myproject.cblproj /p:CodeAnalysisResultsAsErrors=true;RunMicroFocusCodeAnalysisAfterBuild=true;ActiveRulesets="Coding Standards"
Enterprise Developer provides the following properties for code analysis to use with the MSBuild /p switch:
If this property is not specified, MSBuild uses the code analysis properties set in the project's properties. If code analysis is not enabled for the project, MSBuild only performs a build but does not analyze the project.
When this property is specified, any code analysis properties set in the IDE are ignored. This enables you to run command-line specific code analysis jobs that differ from the way code analysis is configured when running builds from within the IDE. The supported options are:
For example:
/p:ActiveRulesets="Coding Standards;Within Entire Program"
You can use Microsoft's own MSBuild switches and properties when performing code analysis. For example, you can use the /maxcpucount switch:
Some of the Microsoft properties you can use with the /p switch are:
For example, setting this to ErrorAndStop means that any errors encountered during code analysis (such as failures to analyze due to some internal error) or the analysis results reported as errors (see TreatWarningsAsErrors) cause the execution to stop.
For more details about using MSBuild from the command line, see the Visual Studio help.
The results of running code analysis from the command line are shown in the command prompt window alongside all the build messages.
The messages have the following format:
[Filename and full path] [LocationInFile (start line, column, end line, column)] : [ErrorMessage (error/warning + output code)] : [RuleSetName] : [Rule] : [Code snippet the location refers to]
For example:
C:\Tutorials\Projects\MyProject\MyProgram.cbl (14,8,14,33): warning MFCA0001 : Within Entire Program : Dead Statements : display "Some Message"