Wednesday, July 18, 2012

Feature Activation/Dependency



http://sharepoint.microsoft.com/Blogs/GetThePoint/Lists/Posts/Post.aspx?ID=607

The possible scopes for Feature Site Template Association features are:


•Farm: Yes

•Web Application: Yes

•Site Collection: Yes

•Web Site: No

Feature Activation Dependencies Introduction

A feature activation dependency expresses a requirement in the relationship between two features.
You can express activation dependencies either for:
  1. Features of the same scope or
  2. Features at a higher scope. This is known as a cross-scoped activation dependency. An example would be a Web site-scoped feature being dependent on a site collection–scoped feature. A better description would be a parent-scoped activation dependency as the dependency is always to a higher level.

Purpose of activation dependencies

Activation dependencies are usually used for feature grouping concepts and feature resource guarantees.

Feature Grouping
When one feature is activated, other features can also be activated automatically. For example, when the default "team collaboration" feature (in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\FEATURES\TeamCollab) is activated, it uses activation dependencies to activate various other features. When you activate the team collaboration feature, it activates the dependent features, and the specified list templates are made available. When you deactivate the feature, the dependent features are deactivated if no other features depend on them, thereby making the list templates unavailable.

Feature Resource Guarantees
A site collection-scoped feature may need to contain resources (for example, a content type) and a Web site-scoped feature to contain an implementation. Activation dependencies can ensure that both features are activated.

Activation Dependency Rules

Activation dependencies must abide by certain rules to avoid, for example, circular dependencies, dependency chains that limit performance, and so on.

Hidden Feature Rules

Only hidden features can be activated or deactivated automatically.
Hidden features cannot have activation dependencies. This means that you must have a visible feature to activate and that you can only activate features from the visible feature. You cannot have a hierarchy of hidden features dependent on each other and have them all automatically activate in the correct order.

Same-Scope Rules

  • Only same-scoped hidden features are automatically activated or deactivated.
  • If a feature is dependent on another feature at the same scope, and the second feature is not activated when the first one is activated, Microsoft SharePoint Foundation activates the second feature.
  • If a feature is deactivated, SharePoint Foundation deactivates a same-scope dependent hidden feature when the last visible feature that has an activation dependency on that hidden feature is deactivated.

Cross-Scope Rules

  • Cross-scope activation dependencies are not supported if the feature depended upon is at a more restrictive scope. For example, a site collection–scoped feature cannot have an activation dependency on a Web site–scoped feature.
  • Feature activation dependencies are not supported across scopes if the feature that is depended upon is not visible.
  • If a feature that is depended upon is not activated, activation of the depending feature fails. For example, if a web site–scoped feature depends on a site collection–scoped feature that is not activated, activation of the web site-scoped feature (or of a site definition that contains a web site-scoped feature) fails.

General Rules

  • Dependencies can work only one level deep. In other words, dependency chains are not supported. SharePoint Foundation does not support more than one level in activation dependencies if the last feature is visible—that is if a visible feature depends on a second visible feature that in turn depends on a third visible feature. However, SharePoint Foundation does support more than one level in activation dependencies if a visible feature depends on a second visible feature that in turn depends on a hidden feature.
  • Activation dependencies can be against hidden or visible features, but hidden features cannot have activation dependencies. The Hidden attribute on the feature element determines whether the feature is displayed in the user interface.

Handling Dependencies Through Feature Stapling

Use Feature Stapling to Avoid Creating Site Definitions

Feature Stapling allows you to "staple" a feature to both out-of-the-box and custom site definitions without modifying them in any way. This means you can add your features to all sites created using that site definition. If you want to make modifications or customizations in out-of-the-box site definitions; develop them all as features and staple them with the respective site definition.

How to staple a Feature to a Site Definition: 

To staple a feature to a site definition, create a stapler feature that will do the stapling. A feature stapled or associated with a site definition is called a staplee feature. Below is an example of a staple feature to staple a Multilanguage feature to the STS, and SPS site definitions:

Stapler Feature.xml


Title="$Resources:MultiLangStaplingFeatureName"

Description="$Resources:MultiLangstaplingFeatureDescription"
Version="12.0.0.0"
Scope="Farm"
xmlns="http://schemas.microsoft.com/sharepoint/"
DefaultResourceFile="_Res">



Elements.xml file (for stapler feature):





In the above Elements.xml file code, you can see the FeatureSiteTemplateAssociation element which basically defines the associations between features and site definitions. In the above example, the stapler feature "staples" the staple feature with the ID "29D85C25-170C-4df9-A641-12DB0B9D4130" to the STS#0, STS#1, and SPS#0 site definitions.


The scope of the stapler feature is always Farm.
If the stapler feature is deactivated, the existing sites will still have the Multilanguage feature activated but no new sites will have the Multilanguage feature activated.
If you want to staple a feature to all site definitions then you can staple it to the GLOBAL (GLOBAL#0) site definition and it will be added to all sites that are created.
To staple to other site definitions, use the table below to determine the name.

Site Templates

Use name column from following table to format the site stapling feature's Elements.xml file. Example: TemplateName="BLOG#0".

Template ID Title Name
0 Global template GLOBAL#0
1 Team Site STS#0
1 Blank Site STS#1
1 Document Workspace STS#2
2 Basic Meeting Workspace MPS#0
2 Blank Meeting Workspace MPS#1
2 Decision Meeting Workspace MPS#2
2 Social Meeting Workspace MPS#3
2 Multipage Meeting Workspace MPS#4
3 Central Admin Site CENTRALADMIN#0
4 Wiki Site WIKI#0
9 Blog BLOG#0
7 Document Center BDR#0
14483 Records Center OFFILE#0
22 Personalization Site SPSMSITE#0
39 Publishing Site CMSPUBLISHING#0
53 Publishing Site BLANKINTERNET#0
53 Publishing Site w Workflow BLANKINTERNET#2
33 News Site SPSNHOME#0
34 Site Directory SPSSITES#0
38 Report Center SPSREPORTCENTER#0
47 Collaboration Portal SPSPORTAL#0
50 Search Center with Tabs SRCHCEN#0
51 Profiles PROFILES#0
52 Publishing Portal BLANKINTERNETCONTAINER#0
54 My Site Host SPSMSITEHOST#0
90 Search Center SRCHCENTERLITE#0
90 Search Center Advance SRCHCENTERLITE#1

FAST Search Center SRCHCENTERFAST#0

Visio Process Repository visprus#0



Stapler Scope and Sequence of Activation

Farm scoped features are activated in this order.
  1. Features from site definition
  2. Features without activation dependencies from stapler
  3. Features with activation dependencies from stapler (in correct sequence)
  4. When using WebApplication scope there does not seem to be any specific order.


Feature Activation Test Results

In performing the following tests I frequently received error messages that referred to web-scoped features as "Site scoped" and site-scoped features as "Site Collection scoped" features. When troubleshooting your own dependencies carefully read any error messages.

Scenario Activation Type Success? Notes
Activate hidden site-scoped feature using staple feature Automatic Yes Staple feature can be used to activate a hidden site-scoped feature.
Activate visible site-scope feature using staple feature Automatic No Staple feature cannot be used to activate a visible site-scoped feature.
Activate hidden web-scoped feature using staple feature Automatic Yes Staple feature can be used to activate a hidden web-scoped feature.
Activate visible web-scoped feature using staple feature Automatic Yes Staple feature can be used to activate visible web-scoped features.
Activate web-scoped feature using a stapled hidden site-scoped feature Automatic No Hidden features cannot activate other features.
Manually activate web-scoped feature with dependency on another visible web-scoped feature Manual Yes Manually activating a web-scoped feature can be used to activate another web-scoped feature.
Manually activate web-scoped feature that has a dependency on a hidden site scoped-feature Manual No Web-scoped feature cannot activate a hidden site-scoped feature. This would be a cross-scoped feature that attempts to activate a feature across scopes to a higher level scope.
Manually activate site-scoped feature using a web-scoped feature Manual No Although web-scoped features can have dependencies on site-scoped features they cannot activate them.


Resources

Activation Dependencies and Scope at MSDN
http://msdn.microsoft.com/en-us/library/aa543162.aspx

Chris O'Brien:The Nuts and Bolts of SharePoint Blog
http://www.sharepointnutsandbolts.com/2007/05/feature-stapling.html

Travis Lingenfelder: Feature Chaining: Activation Dependencies and Feature Stapling
http://blogs.catapultsystems.com/tlingenfelder/archive/2009/06/05/feature-chaining-activation-dependencies-and-feature-stapling.aspx

No comments:

Post a Comment