How to run analysis during TeamBuild |
How to run analysis during TeamBuild |
SharePoint code analysis can also be executed during a TFS Team Build. This helps to ensure the correctness of the SharePoint code. During the Team Build all found errors and warnings are listed in the build result. Additionally the SPCAF reports can be generated and saved to the output directory.
SPCAF supports the Team Build with the following products:
To support TFS 2010 and TFS 2012 SPCAF comes with 2 different build activities which can be integrated into the workflow of a Team Build, depending on the version of TFS. The build activities can be found within the installation directory of SPFAC in subfolder "TeamBuildActivities".
Note: The build activities should not be copied directly into the installation folder of SPCAF because SPCAF searches during analysis within the installation folder for custom rules. As the activities depend on Team Build assemblies they cannot be loaded and SPCAF cannot execute.
Note: If you are not familiar with configuration of team builds in TFS please request somebody to help you. If you like you can reach out to one of our consulting partners who can also help you to analyse the results or implement custom rules.
The following steps provide the general instructions for the Team Build. Some standard TFS configuration steps are skipped.
To run SPCAF on the build server the SPCAF assemblies must be available on the build server. You don't need to install SPCAF on the server!
You should end up as shown in the following screenshot:
Now we need to tell the Build Controller that during a build the SPCAF assemblies should be loaded.
You have 2 options: You can manually add the Build Activity in the xml file or you can use the designer in Visual Studio.
Copy an existing process template, open it in an editor and add the following fragments to the xml to include the SPCAF assembly with the build activity to the template.
To integrate the SPCAF activity into the build process we recommend to add the activity after the finished build and finished tests.
Search for activity with DisplayName "If TestStatus = Unknown" and place the SPCAF activity "RunSharePointCodeAnalysis" after this activity.
NOTE: Because in TFS 2013 the default build process template is a little bit different we need to add a variable to store the path to the Binaries Directory. Open the tab "Variables", add a variable named "BinariesDirectory" with the type "String", you can leave the scope in its default setting (for more information visit Joost Haneveer: How to run SPCAF analysis during TeamBuild in TFS 2013).
If you don't want to add the build activity to the process template in XML you can use a visual designer in Visual Studio.
See below the Visual Studio project with all references, the linked DefaultTemplateSPCAF.xaml
You should end up with the following setup:
The following parameters can be configured for the build activity.
Argument | Description | Sample Value |
---|---|---|
DisplayName | Required String. Title of activity, used in logfiles. | "Run SharePoint Code Analysis SPCAF" |
SettingsFile | Optional String. Name of settings file in folder "/RuleSets" or full path to a different ruleset file. | |
TempFolder | Optional String. Path to temp folder. If not set SPCAF uses a standard temp folder. | |
FailBuildOnError | Optional Boolean. Default FALSE. If TRUE the build fails if SPCAF detects errors. | FALSE |
IgnoreExceptions | Optional Boolean. Default TRUE. TRUE to ignore exceptions during analysis. Settings this value helps to ensure that the build finishes successfully also in case of exceptions. | TRUE |
InputDirectory | Required String. Path to WSP solutions. Can be a folder name or a list of files (separated by ';'). | BinariesDirectory |
LogExceptionStack | Optional Boolean. Default FALSE. In case of problems with SPCAF setting this value to TRUE adds more information to the logfile which describes the error in detail. | FALSE |
OutputFilename | Optional String. Defines the ouptput filename of the reports. Typically the output folder should be in the BinariesDirectory. After successful build the whole BinariesDirectory is copied to the DropLocation. Alternatively the DropLocation or any other folder can be used to save the results. | System.IO.Path.Combine(BinariesDirectory, "SPCAFResults\\SPCAFResults.xml") |
LogFile | Optional String. Defines the path to the log file. | System.IO.Path.Combine(BinariesDirectory, "SPCAFResults\\spcaf.log") |
ReportGeneratorTypes | Optional String. Defines which reports should be created | HTML;XML;DGML;DOCX |
TreatWarningsAsErrors | Optional Boolean. Default FALSE. If TRUE all warnings will be evaluated as errors. | FALSE |
ThrowExceptionOnError | Optional Boolean. Default FALSE. If TRUE an exception will be throw in case of critical errors or errors. | FALSE |
Verbosity | Optional String. Detail level of output (e.g. minimal, default: normal). | normal |
The build activity returns the following values after analysis.
Argument | Description |
---|---|
CriticalErrors | Integer. Contains the number of critical errors after analysis. |
Errors | Integer. Contains the number of errors after analysis. |
CriticalWarnings | Integer. Contains the number of critical warnings after analysis. |
Warnings | Integer. Contains the number of warnings after analysis. |
Information | Integer. Contains the number of information after analysis. |
Now we can use the new process template in a new Build Definiiton
Copyright © 2013 RENCORE AB. All Rights Reserved
Disclaimer: The views and opinions expressed in this documentation and in SPCAF are those of the creators and do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. All trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners. SharePoint Code Analysis Framework, Version 4.5.2.7855, see www.spcaf.com for more information |