Analyzing SharePoint Solutions with MSOCAF (Microsoft SharePoint Online Code Analysis Framework)

Abstract
If we have to audit a SharePoint environment or we are working for a customer in which we are required to deliver solutions with a high standard of quality and the use of best practices in terms of the components being developed, it is very important and recommended to make an exhaustive analysis of these components in order to detect any problem or issues on them before doing any deployment to pre-production or production environments. One of the options we have to perform this analysis is to use the free tool MSOCAF (Microsoft SharePoint Online Code Analysis Framework) provided by Microsoft.

Introduction
If we have to audit a SharePoint environment in terms of the artifacts deployed or we are working for a customer demanding high quality in our development process, it is a good practice to do an exhaustive analysis of the artifacts already deployed or planned to be deployed in order to detect/prevent any issue or problem caused by those artifacts. One of the possibilities for doing that analysis is to use Microsoft SharePoint Online Code Analysis Framework (MSOCAF) provided by Microsoft and available through the following link: https://caf.sharepoint.microsoftonline.com/. You can freely use MSOCAF for analyzing SharePoint solutions and detect any problems introduced by them in a SharePoint farm. In this blog post I will do a first approach about how to use MSOCAF for analyzing SharePoint Solutions.

Installing MSOCAF in a SharePoint development environment
First step in order to start using MSOCAF is to download and install the tool in your SharePoint development environment:
* Open your Internet browser and navigate to the MSOCAF Url. On the page footer, click the MSOCAF link version you want to use. In my case, I’m going to install MSOCAF for SharePoint 2013.

Microsoft SharePoint Online Code Analysis Framework

Microsoft SharePoint Online Code Analysis Framework

* In the next page, you can see the minimum requirements you need (SharePoint 2013 + .NET Framework 4.5 + Windows Installer 3.1 in this case) in order to use MSOCAF and also the related End User License Agreement. Once you accept the License Agreement, you are ready to install MSOCAF by means of the “Install” button.

Microsoft SharePoint Online Code Analysis Framework

Microsoft SharePoint Online Code Analysis Framework – Install

 * Once you the installation process begins, you will be prompted to install additional components like MSOCAF Event Source and Enterprise Library 4.1. Just install them.

• When installation process ends, the MSOCF main window is displayed. As you can see, you can start the analysis of your SharePoint solutions by using the Analyze option. Additionally, you can test a deployment of your SharePoint solutions in the local environment, do a rollback or submit the artifacts to Microsoft just in case you are creating these components for SharePoint Online.

3

Before start using MSOCAF to analyze SharePoint solutions, it is advisable to check the help file that comes with the tool. MOSCAF’s Help file includes a “Custom Rules” section where you can review the details for each rule applied in each test case.

4

For instance, the details for “Check for Use of SP.List.Items” rule are the following:

(a) Check for Use of SPList.Items
If any of the instructions contains the SPList.Items object, MSOCAF will generate an error.
If you encounter problems:
Remove the SPList.Items object from the instructions. For retrieving items in a list, use SPList.GetItems (SPQuery query).For more details, see the MSDN article Best Practices: Common Coding Issues When Using the SharePoint Object Model.

Using MSOCAF
As I have said in the Installation Section, when the installation process ends, the MSOCAF main window is displayed. From here, you can start the analysis of your SharePoint solutions by using the Analyze option. Additionally, you can test a deployment of your SharePoint solutions in the local environment, do a rollback or submit the artifacts to Microsoft just in case you are creating these components for SharePoint Online.

Therefore, start a SharePoint Solutions analysis with MSOCAF is quite straightforward:
* On the MSOCAF main window, just click the Analyze option in order to start the Analysys Wizard. Next MSOCAF window informs about the required folder structure in order to perform a SharePoint solutions analysis using the tool. As you can see, it is mandatory to define such folders and you have to use the same name. Otherwise, you will not be able to start a solutions analysis.

5

 * Once you have created the folder structure, click the “Next” button so next MSOCAF window is shown. This new window contains information about the set of rules that are going to be applied when doing the Analysis. As you can see, the set of rules used by MSOCAF is quite complete. The rules are shown grouped by categories that identify the type of analysis performed and the problems / warnings that can locate. In total, MSOCAF defines 12 categories of rules that internally make use of different analysis tools (FxCop, SPDisposeCheck and CAT.NET): Design, Globalization, Interoperability, Mobility, Naming, Performance, Portability, Usage, Memory Management, Security, Microsoft SharePoint Online Custom Rules and Rules 2013 Upgrade. Digging into these categories, I have found particularly interesting the set of test cases labeled as “Microsoft Online custom rules”. These test cases allow to measure various aspects in the WSPs analyzed such as possible performance problems, design errors, and so on. If you want to know the details about these cases, it’s recommendable to review MOSCAF’s Help.

6

* Next window allows you to specify the path where you have defined the folder structure required by MSOCAF. Once you have added this path, you can start the MSOCAF analysis by clicking the “Analyze” button. In the analysis process, you can be prompted by early errors found by MSOCAF due to problems in the folder structure defined or because the folders are empty. Just cancel the analysis, fix the problems and start again.

* Once everything is fine in terms of folder structure and contents inside the folders, the real analysis starts. For instance, in my case I have analyzed a really dummy SharePoint Solution and as a result, I have obtained a report with the errors and warnings generated by MSOCA. As you will see, this report is really interested for two main reasons:
–  First one, you will have a list of problems or issues that need to be fixed in order to guarantee a safe deployment of your SharePoint solutions. Note that some of the errors dropped by MSOCAF are not necessarily applicable to a SharePoint On-Premise deployment since the tool was designed for SharePoint Online.
–  Second one, you can learn a lot with the MSOCAF analysis since the report will inform you about best practices you should follow when creating SharePoint Solutions: do a good exception handling, use SharePoint Object Model in a right way, etc.

7

*  Depending on the type of error detected by MSOCAF, the results window provides more or less detailed information about it and even how to fix it.

8

Detailed analysis of the results provided by MSOCAF
In order to have a more detailed information about the problems found by MSOCAF, I recommend you to use the “Exceptions”, “Export to excel” and / or “Export to browser” functionalities provided by the tool. The tool provides these three capabilities out of the box so you can have a greater detail in the analysis:
*  Exceptions, provides a detailed report (in. Xml) for exceptions thrown in the analysis of the components.
* Export to Excel format, which allows you to generate an Excel workbook with detailed information about errors and warnings generated by MSOCAF after analyzing the components. The Excel file generated by MSOCAF allows o know problems and warnings generated based on different test cases applied by the tool: design, memory management, etc. As you can see in the Excel file generated, you have the ability to filter the data applying different filters like the test cases used by MSOCAF: “Design”, “Memory management”, “Security”, etc. Additionally, you can apply additional filters in order to narrow specific errors and warnings.

9

* If we opt to use the “Export to Browser” option, the analysis results are shown in a different way compared to the Excel one. Basically, for each analysis rule applied by MSOCAF we can see the problems and warnings found during the analysis process.

10

Certainly, both approaches, “Export to Excel” or “Export to Browser”, provide a great detail about all the errors and warnings generated by MSOCAF after analyzing all the WSPs.

Conclusions
The Development process for the SharePoint platform, as for any other platform, should involve applying a set of quality standards that often are ignored which leads to deploy to pre-production and production environments components and solutions with errors and problems, built without applying best practices, etc.. Fortunately, incorporating tools like MSOCAF to the process of developing SharePoint solutions allows to detect such situations and resolve following the recommendations that the tool itself provides out of the box.

If you have any questions or feedback on Juan Carlos’s article please leave a comment below. We would love to hear from you.

See Juan Carlos’s speak on App’s, SP Apps, New Dev Model, New App Store: The Office Store at ESPC14 for only €1150.

Juan Carlos Juan Carlos González Martín is a Telecommunications Engineer by the University of Valladolid and bachelor in business administration by the Universidad Oberta de Catalunya (UOC). He has more than 10 years of experience in diverse Microsoft products and technologies such as SQL Server, Visual Studio or .NET Framework; although he currently works as a Solutions Architect skilled in SharePoint and Office 365 platforms. Juan Carlos is SharePoint Server MVP since 2008, coordinator of the Cantabria .NET Users Group (Nuberos.Net, www.nuberos.es) and co-founder and coordinator of the following users groups: the SharePoint Users Group of Spain (SUGES, www. suges.es), the Cloud Computing Users Group (CLOUDES) and the recently launched Comunidad de Office 365. He is also co-editor and director of the free Spanish digital magazine about SharePoint: CompartiMOSS (www.compartimoss.com). To date, Juan Carlos has co-authored four books and several articles about SharePoint platform in Spanish and English.

Contact E-Mail: jc.gonzalez@lks.es
Twitter: @jcgm1978
Blog: http://geeks.ms/blogs/jcgonzalez
Web: www.lks.es

Share this on...

Rate this Post:

Share: