Site Provisioning Order

If you ever have gotten stumbled over your features not activating as expected or dependencies not working,  that might have to do with site provisioning order.

SharePoint provisions in the following order:

  1. global onet.xml
  2. SPSite scoped features defined in onet.xml, in the order they are defined in the file.
  3. SPSite scoped stapled features, in quasi random order
  4. SPWeb scoped features defined in onet.xml, in the order they are defined in the file.
  5. SPWeb scoped stapled features, in quasi random order
  6. List instances defined in onet.xml
  7. Modules defined in onet.xml

Implications:

  1. SPSite features should never depend on anything provisoned by an SPWeb feature.  Since generally spweb scoped features are always provisioned after SPSite scoped features, the SPSite scoped feature can't rely on a resource that gets provisioned in an SPWeb scoped feature.
  2. Features can't depend on lists or files provisioned in onet.xml.  Features are provisioned before the actual lists and files which are contained in onet.xml.    However, list instances and files defined in onet.xml can take dependencies on list definitions or list instances defined in features.
  3. List instances and modules defined in onet.xml or within web scoped features listed in the <WebFeatures> tag of onet.xml should never take any dependencies on features that are "stapled".  Stapled features are transient and may not be stapled if the admin adjusts their configuration.