Update 01-09-2017 - SharePoint 2016 Feature Pack 1 brings several functional updates. One of these updates is the "OneDrive for Business Modern Experience." The ODFB Modern experience is not compatible with traditional feature stapling and I have included the powershell steps below to disable/revert it.


How to manage fast site creation when implementing a MySite feature staple in SharePoint 2016

Feature stapling has been around for a long time, and it is still the best way to set custom branding on MySites in SharePoint 2016. The new Fast Site Creation feature for SharePoint 2016 will interfere with traditional feature stapling models without some minimal intervention.

What is Fast Site Creation

SharePoint 2016 introduced a feature called Fast Site Creation (I'll go with FSC so I don't have to type it out). When you enable FSC, it creates a template site collection based on a traditional ONET.xml site definition. When an admin requests a new site collection based on a FSC enabled site definition, SharePoint does a database-level object copy operation rather than run through the steps of provisioning pages, activating features, etc. When you're left with is a much faster site collection provisioning process (hence the name)

Feature Staple Gotcha

At the time of writing this article, FSC is activated by default on the MySite site definition. This means that custom feature staple code will not work without first disabling FSC for the MySite site definition!

Custom feature staple code will not work without first disabling Fast Site Creation

To disable FSC on the MySite site definition, follow the steps outlined in the TechNet Article: SharePoint 2016 Fast Site Creation via PowerShell (Real world example).

If you want to quickly disable FSC without running through every step, this should do the trick.

Disable-SPWebTemplateForSiteMaster –Template SPSPERS#10  

Why does Fast Site Creation Cause Problems

Instead of activating features one-by-one on a new site collection, FSC performs a database copy from a hidden template site collection. If your feature is not activated on the template, it will never be activated for new sites which are based on the template, even if you have configured a feature staple at the farm level.

OneDrive for Business Modern Experience

In order to use feature stapling with SharePoint 2016 AFTER feature pack one (NOV 2016 CU), you will need to disable the OneDrive for Business (ODFB) Modern Experience

$Farm = Get-SPFarm
$Farm.OneDriveUserExperienceVersion = [Microsoft.SharePoint.Administration.OneDriveUserExperienceVersion]::Version1
$Farm.Update()

How to manage Fast Site Creation and Feature Stapling

Traditional feature stapling and FSC can live together peacefully if you can accept some additional deployment/maintenance complexity. If you want to leverage FSC for sites which include feature stapling you will need to update your deployment scripts with a few lines. The general outline pseudocode looks something like this:

#Remove the hidden site template 
Remove-SPSiteMaster -ContentDatabase <content database name> -SiteId <GUID of hidden site template>

#Disable Fast Site Creation
Disable-SPWebTemplateForSiteMaster –Template SPSPERS#10

#Update WSP containing feature staple
Update-SPSolution -identity <solution name> -literalpath <c:\\path\to\wsp>

#Important!  Restart timer service on every farm server or the feature staple will not work
$farm = Get-SPFarm
$farm.TimerService.Instances | foreach { $_.Stop(); $_.Start(); }

#Reactivate FSC for this template
Enable-SPWebTemplateForSiteMaster -Template SPSPERS#10 -CompatibilityLevel 15

#Re-create the template site collection for FSC
New-SPSiteMaster -ContentDatabase team_Content -Template STS#0  

Important Do not forget to restart the SP Timer Service on every server. This has always been required for feature staple

Declarative vs. Custom Code

SharePoint features can include two different types of content

  1. Declarative code - mostly XML based list, column and content type definitions
  2. Custom Code - Code which runs based on event handlers (which are usually configured declaratively)

Custom code is stored in the Global Assembly Cache in the form of DLLs. Since the DLLs are stored in the GAC there should be no need to rebuild the FSC template if you are only updating assemblies stored in the GAC. In this case, restarting IIS and the OWS Timer should do the trick

If, on the other hand you are making declarative updates to your feature staple like adding or removing things like Lists, columns, content types, modules or event receivers, you will likely need to perform all the steps above. Declarative portions of site definitions are deployed by SharePoint during feature activation. Since no features are actually activated during FSC, declarative updates won't be persisted until the hidden site template is updated using the PowerShell steps outlined above.

Additional Resources

SharePoint 2016 Fast Site Creation via PowerShell (Real world example)

SharePoint 2016 MySite activate branding automatically using feature stapling not working

Configure the OneDrive for Business modern user experience

Feature stapling not working for SharePoint 2016

Title Image stapler_Large by TeacherPouch LLC / CC BY-SA-NC 3.0