27
Assuring the Code Quality of SharePoint Solutions and Apps Matthias Einig, MVP RENCORE AB

Assuring the code quality of share point solutions and apps - Matthias Einig

Embed Size (px)

DESCRIPTION

SharePoint development and fun do not always have much in common! Everyone who has ever developed for SharePoint might know what I mean. Even a small SharePoint solution or app consist already of a large number of different files (xml, cs, js, css, resx, jpg, aspx, etc.) which may be implemented and structured differently in every project. Especially with the shift of the development approach to the new App model, SharePoint veterans but also rookies find themselves confronted with many new technologies, frameworks, and coding practices. As a result the quality and maintainability of SharePoint solutions and apps differs very much depending on the experience and preference of the individual developers. In this session we will discuss the common challenges in SharePoint development, as well as the possibilities to standardize the development approach in the team and automatically assure these policies and practices.

Citation preview

Page 1: Assuring the code quality of share point solutions and apps - Matthias Einig

Assuring the Code Quality of

SharePoint Solutions and Apps

Matthias Einig, MVPRENCORE AB

Page 2: Assuring the code quality of share point solutions and apps - Matthias Einig
Page 3: Assuring the code quality of share point solutions and apps - Matthias Einig

Who is that guy?

[email protected]

www.matthiaseinig.de

Matthias EinigCEO, SharePoint MVP

Stockholm, Sweden

Page 4: Assuring the code quality of share point solutions and apps - Matthias Einig

What is Code Quality?

Source: Consortium for IT Software Quality

• Reliability

• Security

• Efficiency

• Maintainability

• Size

Page 5: Assuring the code quality of share point solutions and apps - Matthias Einig

Why should we care?• Avoid bugs

• Reduce effort (coding & testing)

• Improve maintainability

• Prepare for changes/upgrade

• Increase team flexibility

Code Quality can’t be easily added later!

Page 6: Assuring the code quality of share point solutions and apps - Matthias Einig
Page 7: Assuring the code quality of share point solutions and apps - Matthias Einig

How to measure Code Quality?

• Architectural standards

• Coding Practices

• Complexity

• Documentation

• Portability

• Tech./Func. Volume

Reliability

Security

Efficiency

Maintainability

Size

Page 8: Assuring the code quality of share point solutions and apps - Matthias Einig

How to analyse Code Quality?

• Static vs. Dynamic

• Source Code vs. Object Code

• Manual vs. Automated

• Ad hoc vs. Continuously

Page 9: Assuring the code quality of share point solutions and apps - Matthias Einig

Why is it important for SharePoint?• Solutions / apps are black boxes

• Code quality differs a lot

• Solutions change (ALM)

• Complexity

• Policies / Best Practices

• Dev Teams Change

• Farm stability / security / licensing

Page 10: Assuring the code quality of share point solutions and apps - Matthias Einig

So, what is SharePoint Code? .NET code

XML: Manifest, Features, Content Types, Templates

HTML, ASPX, ASCX

CSS, JavaScript

Images, resources, document templates…

Deployment locations!

Page 11: Assuring the code quality of share point solutions and apps - Matthias Einig

Is my codecorrect and follows

best practices?

Developer

Is the codewell designed and

maintainable?Architect

Does the codecomply with

company policiesand standards?

Quality Manager

Who needs it and why?

Will the codeharm my farm?

Administrator

Page 12: Assuring the code quality of share point solutions and apps - Matthias Einig

What Tools do we have?`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)

Analyzes code security

(not SharePoint-specific)

Checks memory leaks

(SharePoint-specific)

Combination of FxCop and

SPDisposeCheck for SharePoint Online

Page 13: Assuring the code quality of share point solutions and apps - Matthias Einig

The Gap…What’s missing?• Analyze SharePoint specific code quality!

• Analyze SharePoint dependencies!

• Gather SharePoint metrics!

• Document the SharePoint solution / app!

• Assess the migratability to the app model!

Page 14: Assuring the code quality of share point solutions and apps - Matthias Einig

Commerical Products

Free version

SPCop Community Edition

Free version

SPCAF Migration Assessment

Page 15: Assuring the code quality of share point solutions and apps - Matthias Einig

CODE ANALYSIS

WITH SPCAF

Page 16: Assuring the code quality of share point solutions and apps - Matthias Einig

• Run SPCAF manually or on solution build

• Doubleclick results in Error List to open the

line of code

SPCAF in Visual Studio

Page 17: Assuring the code quality of share point solutions and apps - Matthias Einig

SPCAF Client Application

Page 18: Assuring the code quality of share point solutions and apps - Matthias Einig

Use predefined rulesetse.g. SP2013 Compatibility

Create your own ruleset

Enable/disable rules

Adjust severity of notifications

Information

Warning

Error

Configure Rulesets

Page 19: Assuring the code quality of share point solutions and apps - Matthias Einig

Run SPCAF in TeamBuild as Quality Gate

• Custom Build Activity

• Supports TFS 2010/2012/2013, VS Online, Team City etc.

Build in TFS on-premises Build in Visual Studio Online

Continuous Integration

Page 20: Assuring the code quality of share point solutions and apps - Matthias Einig

DEVELOP CUSTOM RULES

Page 21: Assuring the code quality of share point solutions and apps - Matthias Einig

You want to rule yourself? (1)

using SPCAF.Sdk;using SPCAF.Sdk.Rules;using SPCAF.Sdk.Model;using SPCAF.Sdk.Model.Extensions;

1. Create empty class library

2. Add SPCAF.SDK.dll assembly reference

3. Create class and add usings

4. Add method stub by inheriting from ”Rule”

namespace SP24.Rules{

public class FeatureNameStartsWithSP24 : Rule<FeatureDefinition>{

public override void Visit(FeatureDefinition target, NotificationCollectionnotifications)

{}}}

Page 22: Assuring the code quality of share point solutions and apps - Matthias Einig

5. Add Rule Metadata

namespace SP24.Rules{

[RuleMetadata(typeof(Naming),CheckId = "SPC99001",DisplayName = "Feature name should start with SP24",Description = "A feature name should be prefixed with 'SP24'.",DefaultSeverity = Severity.Warning,SharePointVersion = new string[] { "12", "14", "15" },Message = "Feature '{0}' should start with 'SP24'.",Resolution = "Change the folder name of the feature and add the name at the beginning,

e.g.‘SP24.Intranet.Components.ContentTypesFeature'.")]public class FeatureNameStartsWithSP24 : Rule<FeatureDefinition>{...

You want to rule yourself? (2)

Page 23: Assuring the code quality of share point solutions and apps - Matthias Einig

7. Build and drop the assembly into the SPCAF installation folder

public class FeatureNameStartsWithSP24 : Rule<FeatureDefinition>{

public override void Visit(FeatureDefinition target, NotificationCollection notifications){

if (!target.FeatureName.StartsWith("SP24")){

string message = string.Format(this.MessageTemplate(), target.FeatureName);Notify(target, message, notifications);

}}

}

6. Implement the rule

You want to rule yourself? (3)

Page 24: Assuring the code quality of share point solutions and apps - Matthias Einig

Summary• Code Quality must not be a fluke!

• Helps you to find problems earlier

• Saves your time & money

• Prepares you for changes and upgrades

• QA can be implemented in several steps

Also check out my session:

SharePoint Continuous Integration with VS Online and Azure

D2S3DEV 10/16/2014 11:30 AM

Page 25: Assuring the code quality of share point solutions and apps - Matthias Einig

References• SharePoint Code Analysis Framework

spcaf.com

• Free SPCop Code Checkgo.spcaf.com/spcopceI

• Free SPCAF Code Migration Assessmentgo.spcaf.com/spcafma

• SharePoint health check: Extracting SP Customizationsurl.spcaf.com/extract

Page 26: Assuring the code quality of share point solutions and apps - Matthias Einig

questions?

WWW.MATTHIASEINIG.DE

@MATTEIN

Page 27: Assuring the code quality of share point solutions and apps - Matthias Einig

thank you.

SHAREPOINT AND PROJECT CONFERENCE ADRIATICS

ZAGREB, 10/15/2014 - 10/16/2014