Automated Code Quality Analysis of SharePoint Solutions


Published on

These are my slides from the SharePoint konferenz in Vienna on 17th/18th of June 2013

SharePoint development and fun do not always have much in common! Everyone who has ever developed for SharePoint in Visual Studio might know what I mean. Even a small SharePoint solution consist already of a large amount of different files (xml, cs, js, css, resx, jpg, aspx, etc) which may be structured differently depending on the preferences and experience of the developer.
Particularly the extensive XML Schema for manifest.xml, feature.xml, element.xml, Content Types, List Definitions, etc. is an endless source of surprise and cannot be debugged at all in Visual Studio. As a way out, many developers choose to develop standard SharePoint artefacts programmatically rather than following the declarative approach which make the solutions even more complex.
As a result it is really hard to analyze SharePoint solutions, find violations against the XML schema, best practices, coding guidelines or to pinpoint performance sinks and cyclomatic dependencies of artefacts.
Neither Visual Studio nor other tools like FXCop, StyleCop etc. allow to perform SharePoint specific automatic code analysis.
This session will show the SharePoint Code Analysis Framework (SPCAF) which addresses exactly this gap and you will learn how to easily develop your own rules for it.
SPCAF is available at

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Automated Code Quality Analysis of SharePoint Solutions

  1. 1. Platin-Partner: Gold-Partner: Veranstaltungs-Partner: Medien-Partner:Automated Code Quality Analysis ofSharePoint SolutionsMatthias Einig
  2. 2. Contact@matteinmail@matthiaseinig.dewww.matthiaseinig.deWho is that guy?• SharePoint developer since SPS2003• MCSE, MCPD, MCITP, MSCA inSharePoint 2007-2013• SCRUM Master and Product OwnerMatthias EinigSharePoint ArchitectSteria AB, www.steria.comStockholm, SwedenMain Focus:• Solution Architecture,• Solution Development,• SharePoint ALM,• Solution Quality
  3. 3. What is Code Analysis? Static vs. Dynamic Source Code vs. Object Code Manual vs. Automated Coding Errors, Best Practices Metrics
  4. 4. Why is it so important for SharePoint? Solutions / apps are black boxes Code quality differs a lot Solutions change (ALM) Complexity complicatesmaintainability Farm stability / security / licensing needs to beassured Policies / best practices are hard to enforce
  5. 5. So, what the heck is SharePoint Code? .NET code using SP API XML Files: Manifest,Features, Content Types,Web Templates etc. HTML, ASPX, ASCX CSS, JavaScript Resources: images, resx, document templates… Deployment locations!
  6. 6. Is my codecorrect and followsbest practices?DeveloperWill the codeharm my farm?AdministratorIs the codewell designed andmaintainable?ArchitectDoes the codecomply withcompany policiesand standards? QualityManagerWho needs it and why?
  7. 7. ObjectCode FxCop/VSCAFxCop MetricsCAT.netSourceCode StyleCopSPCode SPDisposeCheckMSOCAFChecks against general coding errors(not SharePoint-specific)Calculates code metrics(only .NET code, not SharePoint specific)Checks coding style guidelines(only .NET code, not SharePoint specific)Analyses code security(not SharePoint-specific)Checks memory leaks(SharePoint-specific)Combination of FxCop andSPDisposeCheck for SharePoint OnlineWhat do we have right now?
  8. 8. What’s missing? No tool to check all SharePoint specific Code Analyze solution dependencies Calculate SharePoint metrics Show what’s inside the solution / app!
  9. 9. The Solution!
  10. 10. Identifies codingviolations against~400 rulesVisualizesdependenciesbetweenSharePointelementsCalculates metricson SharePointCodeCreates contentreports of packagesWhat is in it?
  11. 11. DEMOVisual Studio Integration
  12. 12. SPCAF 4 Visual Studio• Run SPCAF manually or onsolution build• Doubleclick results in Error Listto open the line of code
  13. 13. Configure Rulesets• Use predefined settingsi.e SP2013 Compatibility• Create your own settings• Enable/disable rules• Adjust severity of notifications• Information• Warning• Error
  14. 14. Continuous IntegrationRun SPCAF in TeamBuild as Quality Gate• Custom Build Activity• Supports TFS 2010/2012 and Team Foundation Service (Cloud)Build in TFS on-premises Build in Team Foundation Services
  15. 15. Client Applications• SPCAF runs on Azure (WCF Service)• Available Clients:Windows 8 App Desktop Client (WPF) Web Client (Silverlight)SPCAF on Azure
  16. 16. DEMODesktop Client
  17. 17. SPCAF Desktop/Online
  18. 18. DEMODevelop custom rules for SPCAF
  19. 19. 1. Create empty class library2. Add SPCAF.SDK.dll assemblyreference3. Create class and add usings4. Add method stub by inheriting from ”Rule”You want to rule yourself? (1)using SPCAF.Sdk;using SPCAF.Sdk.Rules;using SPCAF.Sdk.Model;using SPCAF.Sdk.Model.Extensions;namespace SPKonfAT.Rules{public class FeatureNameStartsWithSPKonfAT : Rule<FeatureDefinition>{public override void Visit(FeatureDefinition target, NotificationCollectionnotifications){}}}
  20. 20. You want to rule yourself? (2)5. Add Rule Metadatanamespace SPKonfAT.Rules{[RuleMetadata(typeof(Naming),CheckId = "SPC99001",DisplayName = "Feature name should start with SPKonfAT",Description = "A feature name should be prefixed with SPKonfAT.",DefaultSeverity = Severity.Warning,SharePointVersion = new string[] { "12", "14", "15" },Message = "Feature {0} should start with SPKonfAT.",Resolution = "Change the folder name of the feature and add the name at the beginning,e.g.SPKonfAT.Intranet.Components_ContentTypesFeature.")]public class FeatureNameStartsWithSPKonfAT : Rule<FeatureDefinition>{...
  21. 21. You want to rule yourself? (3)7. Build and drop the assembly into SPCAF installation folderpublic class FeatureNameStartsWithSPKonfAT : Rule<FeatureDefinition>{public override void Visit(FeatureDefinition target, NotificationCollectionnotifications){if (!target.FeatureName.StartsWith("SPKonfAT")){string message = string.Format(this.MessageTemplate(), target.FeatureName);Notify(target, message, notifications);}}}6. Implement the ruleRead more about the SDK at
  22. 22. What was that again?SharePoint Code Analysis• is important for EVERYBODY • improves solution quality• improves farm stabilitySPCAF• fills the tooling gap• runs locally and in the cloud• integrates in the ALM process• is extensible
  23. 23. Where do I get it?Download SPCAF BETA for free atwww.spcaf.comMatthias Einig@matteinwww.matthiaseinig.deFollow us!TheSharePointCodeQualityTeamTorsten Code Quality Tools
  24. 24. FRAGEN ?
  25. 25. SharePoint Campab 08. Juli in Münchenab 05. August in Berlinab 02. September in Karlsruhein zwei speziellen Versionenwww.SharePointCamp.deTrainings und Events der ppedvMehr als 100 verschiedene Trainings aufMicrosoft-Technologien spezialisiert11 Standorte in AT & D Maßgeschneiderte Trainings direkt bei Ihnen vor Ort!www.ppedv.atWir sehen uns wieder!
  26. 26. Hat Ihnen mein Vortrag gefallen?Ich freue mich auf Ihr Feedback!
  27. 27. VIELEN DANK!Platin-Partner: Gold-Partner: Veranstaltungs-Partner: Medien-Partner: