SharePoint Site Definition Provisioning Order

When you use site definitions to create sites it's often pretty unclear what the order is in which the sites are provisioned. Knowing the order can be important if you want to make several changes to your site that are dependent on each other. In that case you need to know how to make sure that the changes are executed in the right order.

Site Definition Provisioning Order

  1. Url for the site is created
  2. Global onet.xml is provisioned
  3. Site collection (SPSite) scoped features defined in onet.xml are activated in the order in which they are listed in the onet.xml
  4. Site collection scoped stapled features are activated in random order
  5. Site(SPWeb) scoped features defined in onet.xml are activated in the order in which they are listed in the onet.xml
  6. Site (SPWeb) scoped stapled features in activated in random order
  7. Listinstances defined in onet.xml are created
  8. Modules defined in onet.xml are processed (and thus this is the moment at which the default. aspx file  and other aspx files defined in the modules are added to the site)

This list tells you that if the order in which features are activated is important and you want to use feature stapling you should create dependent features.
This also tells you that the default.aspx page is the last thing that is added to the site. If you want to make changes to this file like moving around web parts on the page, or adding web parts to the page you there are a couple of ways you can go about this:

  1. You can create a feature that provisions the default.aspx page and associate another feature with that one that will contain a featurereceiver that makes changes to the default.aspx page.  – This is the recommended way to go about this
  2. You can create a web control on the master page that will be executed only once – This is recommended for adjusting the MySites. Steve Peschka wrote a great blog post about this
  3. You can use the ExecuteUrl element in the onet.xml. You can add a hyperlink to a custom aspx page to the ExecuteUrl. This page will be opened after the site is created. You can have the custom page make the changes you want to.
  4. You can create a custom provisioning provider, which adds the capability to hook custom code to be executed after the site has been created.