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.url for the site is created

  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  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  random order

  6. List instances defined in onet.xml

  7. Modules defined in onet.xml ( 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)

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 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.

  4. 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 http://blogs.msdn.com/sharepoint/archive/2007/03/22/customizing-moss-2007-my-sites-within-the-enterprise.aspx

(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.

原文链接:http://www.sharepointchick.com/archive/2009/04/29/site-definition-provisioning-order.aspx

http://blogs.msdn.com/b/mcsnoiwb/archive/2008/05/28/site-provisioning-order.aspx