Writing better SharePoint code with SPCAF and Visual Studio

Mobile Man / Monday, March 30, 2015

Even the best developers can make mistakes, and on a big build it’s crucial that you feel confident your coding is error-free. This is no different when developing SharePoint apps. Of course, comprehensive development guidelines are a good way to start here, but they still require manual verification and fixes. Wouldn’t life be so much simpler if this process could be automated?

Visual Studio has partially responded to this need by building tools which analyze code using code analysis tools. However, while great for general development, Visual Studio doesn’t focus on SharePoint specific development guidelines. To write better code, SPCAF (SharePoint Code Analysis Framework) from Rencore provides an excellent tool to analyze custom SharePoint apps and solutions. In this post we’ll be looking into the features of this tool when building SharePoint apps, with many also applying to farm solutions.

Analyze your code

SPCAF validates and tests your custom-made code through the application of about 600 rules. By following these rules, your solution can avoid XML errors, follow best practices, is future-proofed and so forth. In addition, custom rules can be added to adhere to a company’s standards around development. Reports are produced which not only contain the errors found, but which also provide a suggested solution. See what this looks like in practice here.

Write better apps

SPCAF can analyze both SharePoint apps and Farm solutions. To analyze apps, the team at Rencore have assembled a set of rules tailored to apps. For example, SPCAF will verify that the app meets the guidelines for submission to the store; store submission of SharePoint apps can be time consuming so SPCAF helps when you’re trying to find and solve these errors.

The quality of an app can be further enhanced through the application of a set of correctness rules. For example, only 25 Supported Locales are supported in an app; SPCAF throws up an error if more than 25 locales have been added.

Integration with third party apps

Most developers are already accustomed to using applications such as FxCop for analyzing .Net code, or CSS Lint to analyze CSS files. SPCAF handily provides integration with a lot of these third party apps, and it will nicely integrate these results into the SPCAF reports too. By integrating these external tools, one application (SPCAF) is responsible for analyzing the app and combining these results into a report. That should help make your job a lot easier!

Run from Visual Studio

Visual Studio is the most important tool for a developer. While SPCAF can be run from the command line, it provides full integration with Visual Studio. Analysis can be configured to run on every build, and the build can fail whenever SPCAF detects an error. By defining such rules in the build configuration, an app that did not pass the SPCAF rules (plus configured 3rd party apps) will never make it to other environments.

Furthermore, it even allows for automated analysis by a TFS build server on, for example, each check in. A check in will fail when an error was encountered during SPCAF analysis.

Write better code in less time

Every software developer makes mistakes and like in any type of engineering, the earlier a mistake is discovered, the better. By using automated code analysis tools, errors and problems can be discovered sooner rather than later and headaches avoided when you’re trying to find out what went wrong.

SPCAF provides a rich set of features to analyze SharePoint apps in different areas, like code correctness, best practices, and upgradeability. In this way it will decrease development time (making you more efficient) because it outlines the issues and provides guidelines on how to solve them.