These are my slides from the SharePoint konferenz in Vienna on 17th/18th of June 2013 http://www.sharepointkonferenz.at
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 www.spcaf.com
2. Contact
@mattein
mail@matthiaseinig.de
www.matthiaseinig.de
Who is that guy?
• SharePoint developer since SPS2003
• MCSE, MCPD, MCITP, MSCA in
SharePoint 2007-2013
• SCRUM Master and Product Owner
Matthias Einig
SharePoint Architect
Steria AB, www.steria.com
Stockholm, Sweden
Main Focus:
• Solution Architecture,
• Solution Development,
• SharePoint ALM,
• Solution Quality Assurance
sharepoint-community.net
3. What is Code Analysis?
Static vs. Dynamic
Source Code vs. Object Code
Manual vs. Automated
Coding Errors, Best Practices
Metrics
4. Why is it so important for SharePoint?
Solutions / apps are black boxes
Code quality differs a lot
Solutions change (ALM)
Complexity complicates
maintainability
Farm stability / security / licensing needs to be
assured
Policies / best practices are hard to enforce
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. 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? QualityManager
Who needs it and why?
7. ObjectCode FxCop/VSCA
FxCop Metrics
CAT.net
SourceCode StyleCop
SPCode SPDisposeCheck
MSOCAF
Checks 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 and
SPDisposeCheck for SharePoint Online
What do we have right now?
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!
10. Identifies coding
violations against
~400 rules
Visualizes
dependencies
between
SharePoint
elements
Calculates metrics
on SharePoint
Code
Creates content
reports of packages
What is in it?
12. SPCAF 4 Visual Studio
• Run SPCAF manually or on
solution build
• Doubleclick results in Error List
to open the line of code
13. Configure Rulesets
• Use predefined settings
i.e SP2013 Compatibility
• Create your own settings
• Enable/disable rules
• Adjust severity of notifications
• Information
• Warning
• Error
14. Continuous Integration
Run 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. Client Applications
• SPCAF runs on Azure (WCF Service)
• Available Clients:
Windows 8 App Desktop Client (WPF) Web Client (Silverlight)
SPCAF on Azure
19. 1. Create empty class library
2. Add SPCAF.SDK.dll assemblyreference
3. Create class and add usings
4. 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, NotificationCollection
notifications)
{}
}
}
20. You want to rule yourself? (2)
5. Add Rule Metadata
namespace 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. You want to rule yourself? (3)
7. Build and drop the assembly into SPCAF installation folder
public class FeatureNameStartsWithSPKonfAT : Rule<FeatureDefinition>
{
public override void Visit(FeatureDefinition target, NotificationCollection
notifications)
{
if (!target.FeatureName.StartsWith("SPKonfAT"))
{
string message = string.Format(this.MessageTemplate(), target.FeatureName);
Notify(target, message, notifications);
}
}
}
6. Implement the rule
Read more about the SDK at http://matte.in/SPCAFSDK
22. What was that again?
SharePoint Code Analysis
• is important for EVERYBODY
• improves solution quality
• improves farm stability
SPCAF
• fills the tooling gap
• runs locally and in the cloud
• integrates in the ALM process
• is extensible
23. Where do I get it?
Download SPCAF BETA for free at
www.spcaf.com
Matthias Einig
@mattein
www.matthiaseinig.de
Follow us!
TheSharePointCodeQualityTeam
Torsten Mandelkow
@tmandelkow
blogs.msdn.com/b/torstenmandelkow
SPCAF
@spcaf
www.spcaf.com
SharePoint Code Quality Tools
25. SharePoint Camp
ab 08. Juli in München
ab 05. August in Berlin
ab 02. September in Karlsruhe
in zwei speziellen Versionen
www.SharePointCamp.de
Trainings und Events der ppedv
Mehr als 100 verschiedene Trainings auf
Microsoft-Technologien spezialisiert
11 Standorte in AT & D Maßgeschneiderte Trainings direkt bei Ihnen vor Ort!
www.ppedv.at
Wir sehen uns wieder!
26. Hat Ihnen mein Vortrag gefallen?
Ich freue mich auf Ihr Feedback!