This document discusses the importance of assuring code quality for SharePoint solutions and apps. It defines code quality as reliability, security, efficiency, maintainability and size. Poor code quality can lead to bugs, increased development and testing efforts, and difficulties with maintenance. While tools exist to analyze .NET code quality, there is a gap for analyzing SharePoint-specific code. The document introduces the SharePoint Code Analysis Framework (SPCAF) tool, which allows analyzing SharePoint code for quality issues, dependencies, metrics and compliance with standards. It also enables custom rule development. Regular code quality checks with SPCAF can help improve solutions, catch issues early, and prepare code for upgrades and changes.
8. How to analyse Code Quality?
• Static vs. Dynamic
• Source Code vs. Object Code
• Manual vs. Automated
• Ad hoc vs. Continuously
9. 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
11. Is my code
correct and follows
best practices?
Developer
Is the code
well designed and
maintainable?
Architect
Does the code
comply with
company policies
and standards?
Quality Manager
Who needs it and why?
Will the code
harm my farm?
Administrator
12. 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
13. 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!
18. Use predefined rulesets
e.g. SP2013 Compatibility
Create your own ruleset
Enable/disable rules
Adjust severity of notifications
Information
Warning
Error
Configure Rulesets
19. 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
21. 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, NotificationCollection
notifications)
{}
}}
22. 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)
23. 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)
24. 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