spsaturday sydney 2013 - analysing sharepoint code with spcaf
DESCRIPTION
Slides from the SharePoint Saturday Sydney 2013 session about Analysing SharePoint code with SPCAF. The SharePoint Code Analysis Framework (SPCAF) is a set of tools created by Torsten Mandelkow and Matthias Einig. You can use the tools to examine .WSP files and .APP files to compare against a set of 400 rules, analyze dependencies, calculate metrics and more. In this session, I am going to take you through a tour of the SPCAF features, discuss the pros and cons of using it, show you how to integrate it with Team Foundation Server (TFS) and how you can add your own custom rules. If you spend time developing or managing SharePoint code, this is the session you have been waiting for. Most of the slides are based on original SPCAF presentation by Matthias Einig, and were used with Matthias Einig permission. More information could be found here: http://spsevents.org/worldwide/Sydney/Pages/Sessions.aspx http://www.spcaf.com http://spdevlab.com/TRANSCRIPT
Major Sponsors Minor Sponsors
Analyzing SharePoint Code with SPCAFAnton Vishnyakov SharePoint Consultant/Developer
Anton VishnyakovSoftware Engineer, Ensysthttp://ensyst.com.auContacts
@[email protected]://spdevlab.com
SharePoint Consultant/Developer
MCTS/MCPD/MCITP
Main Focus:
• Solution Architecture• Solution Development
What is the code analysis?
Why is it important for SharePoint?
SPCAF! SPCAF! SPCAF!
Agenda
Static vs. Dynamic
Source Code vs. Object Code
Manual vs. Automated
Coding Errors
Best Recommended Practices
Metrics
What is Code Analysis
Solutions / apps are black boxes
Code quality differs a lot
Solutions change (ALM)
Complexity complicatesmaintainability
Farm stability / security
Policies / best practices are hard to enforce
Why is it so important for SharePoint?
.NET code using SP API
XML Files: Manifest, Features, Content Types, Web Templates
HTML/ASPX/ASCX/CSS/JS/XSLT
Resources: images, resx, document templates…
Deployment locations!
… And 100500 more «very small details»
So, what the heck is SharePoint Code?
Who needs it and why?
Who needs it and why?
Developer
Who needs it and why?
Is my code correct
and follows
best practices?
Developer
Who needs it and why?
Is my code correct
and follows
best practices?
DeveloperAdministrator
Who needs it and why?
Is my code correct
and follows
best practices?
Developer
Will the code harm my
farm?
Administrator
Architect
Who needs it and why?
Is my code correct
and follows
best practices?
Developer
Will the code harm my
farm?
Administrator
Who needs it and why?
Is my code correct
and follows
best practices?
Developer
Will the code harm my
farm?
Administrator
Is the code well
designed and maintainable
?
Architect
Quality Manager
Who needs it and why?
Is my code correct
and follows
best practices?
Developer
Will the code harm my
farm?
Administrator
Is the code well
designed and maintainable
?
Architect
Who needs it and why?
Is my code correct
and follows
best practices?
Developer
Will the code harm my
farm?
Administrator
Is the code well
designed and maintainable
?
Architect
Does the code comply with
company policies and standards?
Quality Manager
Object codeFxCop/VS CAFxCop MetricsCAT.net
Checks against general coding errors (not SharePoint-specific)
Calculates code metrics (only .NET code, not SharePoint specific)
Analyses code security (not SharePoint-specific)
Source codeStyleCop Checks coding style guidelines
(only .NET code, not SharePoint specific)
SharePoint codeSPDisposeCheck
MSOCAF
Checks memory leaks (SharePoint-specific)
Combination of FxCop and SPDisposeCheck for SharePoint Online
What is missing?
No tool to check all SharePoint specific Code
Analyze solution dependencies
Calculate SharePoint metrics
Show what’s inside the solution / app!
The Solution!
What is in it?
Identifies coding violations against ~400 rules
Visualizes dependencies between SharePoint elements
Calculates metrics on SharePoint Code
Creates content reports of packages
SPCAF VS Integrationdemonstration
Continuous Integration and TFS
Run SPCAF in TeamBuild as Quality Gate
Custom Build Activity
Supports TFS 2010/2012 and TFS Online (Cloud)
Build in TFS on-premisesBuild in Team Foundation Services
Client Applications
SPCAF runs on Azure (WCF Service)
Available Clients:
Windows 8 AppDesktop Client (WPF)
Web Client (Silverlight)
SPCAF on Azure
SPCAF Desktop Clientdemonstration
SPCAF Extensibilitydemonstration
Ruling the world! – step 1/3using SPCAF.Sdk;using SPCAF.Sdk.Rules;using SPCAF.Sdk.Model;using SPCAF.Sdk.Model.Extensions;
namespace SPSaturday.Rules{ public class FeatureStartsWithSPSaturday : Rule<FeatureDefinition> { public override void Visit(FeatureDefinition target, NotificationCollection notifications) {} }}
Ruling the world! – step 2/3namespace SPSaturday.Rules{ [RuleMetadata(typeof(Naming), CheckId = "SPC99001", DisplayName = "Feature name should start with SPSaturday", Description = "A feature name should start with 'SPSaturday'.", DefaultSeverity = Severity.Warning, SharePointVersion = new string[] { "12", "14", "15" }, Message = "Feature '{0}' should start with 'SPSaturday'.", Resolution = "Change feature name to start with 'SPSaturday'”)] public class FeatureStartsWithSPSaturday : Rule<FeatureDefinition> { ...
Ruling the world! – step 3/3public class FeatureStartsWithSPSaturday : Rule<FeatureDefinition>{
public override void Visit(FeatureDefinition target, NotificationCollection notifications)
{ if (!target.FeatureName.StartsWith("SPSaturday"))
{ var message = string.Format(MessageTemplate(), target.FeatureName); Notify(target, message, notifications); }
}}
SharePoint Code Analysis
is important for EVERYBODYimproves solution quality improves farm stability
SPCAFfills the tooling gap runs locally and in the cloudintegrates in the ALM processis extensible
Action plan! Follow SPCAF team!
Matthias [email protected]
Torsten Mandelkow@tmandelkow
SPCAF@spcaf www.spcaf.com
Download SPCAF at www.spcaf.com
Improve your solutions
Feedback the enhancements
Write your own rules/metrics
Share your story with SPCAF
Question and Answer
Questions?Comments?More info
Contact details:[email protected]
@avishnyakov
http://spdevlab.com
Related links:
SharePoint Code Analysis Framework (SPCAF)
SharePoint Code Analysis Framework (SPCAF) – Documentation
First impression of SPCAF – SharePoint Code Analysis Framework: code analysis, metrics, rules and dependencies
Writing your second rule for SPCAF – big brother watches your code!
Writing your first metric for SPCAF – put the best practices in place!
Writing your first rule for SPCAF – put the best practices in place!
Codeplex: SPCAF Contrib – http://spcafcontrib.codeplex.com
Twitter: @SPCAF #SPCAF
Support: [email protected]
Feedback: [email protected]
Major Sponsors Minor Sponsors
Thanks for listeningRemember to submit your feedback so you go in the draw to win prizes at the end of the day