Monday, March 22, 2010

Feature Activation Dependency – Activating multiple features using single feature

Feature activation dependency means activating multiple hidden features internally on activating a single visible feature. There are some rules to be followed for feature activation dependency

  1. There should be a single visible feature, and a set of hidden features. On activating this visible feature should activate all the hidden features.

  2. All the features should be scoped at the same level i.e either to "Web,
    Site, Web Application or Farm" level.

You might ask me when we will use this Feature activation dependency.

Let's consider a scenario. Let's assume we have created couple of SharePoint List Definitions and we want to please them in a single SharePoint solution and active them in a single feature as shown below.




As we can see from the above there are four "SharePoint Custom list definitions" and a single feature which provisions all these Custom List Definitions.


That single feature definition code actually looks like this…
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="2f53989d-5799-4f65-bce8-0e1e7c1ae6c4"
Title="Fax Log"
Description="Description for Fax Log"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Web"
DefaultResourceFile="core"
ImageUrl="GenericFeature.gif"
ReceiverAssembly="FaxLog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=53432c81e5329871"
ReceiverClass="FaxLog.FeatureReceiver"
xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
<ActivationDependencies>
<!--Currency Custom List -->
<ActivationDependency FeatureId="5E134998-AA1B-44bb-A553-6F9B75DC5AB1" />
<!--Customers Profile Custom List -->
<ActivationDependency FeatureId="01238751-CD20-4edf-9833-80C610850DA5" />
<!--Branch Total Custom List -->
<ActivationDependency FeatureId="C2306EDC-338B-4073-807B-6132512FA9CA" />
<!--Fax Log Custom List -->
<ActivationDependency FeatureId="B35CE3FE-B4FB-4a66-B817-5C418FAA0682" />
</ActivationDependencies>
</Feature>
Even Microsoft does same thing for creating all the lists, while provisioning a SharePoint site. See the feature code for team site provisioning.


<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" Title="$Resources:core,teamcollabFeatureTitle;" Description="$Resources:core,teamcollabFeatureDesc;" ImageUrl="WssTeamCollaborationFeature.gif" ImageUrlAltText="" Scope="Web" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/">
<ActivationDependencies>
<ActivationDependency FeatureId="00BFEA71-D1CE-42de-9C63-A44004CE0104" />
<!-- AnnouncementsList Feature -->
<ActivationDependency FeatureId="00BFEA71-7E6D-4186-9BA8-C047AC750105" />
<!-- ContactsList Feature -->
<ActivationDependency FeatureId="00BFEA71-DE22-43B2-A848-C05709900100" />
<!-- CustomList Feature -->
<ActivationDependency FeatureId="00BFEA71-F381-423D-B9D1-DA7A54C50110" />
<!-- DataSourceLibrary Feature -->
<ActivationDependency FeatureId="00BFEA71-6A49-43FA-B535-D15C05500108" />
<!-- DiscussionsList Feature -->
<ActivationDependency FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" />
<!-- DocumentLibrary Feature -->
<ActivationDependency FeatureId="00BFEA71-EC85-4903-972D-EBE475780106" />
<!-- EventsList Feature -->
<ActivationDependency FeatureId="00BFEA71-513D-4CA0-96C2-6A47775C0119" />
<!-- GanttTasksList Feature -->
<ActivationDependency FeatureId="00BFEA71-3A1D-41D3-A0EE-651D11570120" />
<!-- GridList Feature -->
<ActivationDependency FeatureId="00BFEA71-5932-4F9C-AD71-1557E5751100" />
<!-- IssuesList Feature -->
<ActivationDependency FeatureId="00BFEA71-2062-426C-90BF-714C59600103" />
<!-- LinksList Feature -->
<ActivationDependency FeatureId="00BFEA71-F600-43F6-A895-40C0DE7B0117" />
<!-- NoCodeWorkflowLibrary Feature -->
<ActivationDependency FeatureId="00BFEA71-52D4-45B3-B544-B1C71B620109" />
<!-- PictureLibrary Feature -->
<ActivationDependency FeatureId="00BFEA71-EB8A-40B1-80C7-506BE7590102" />
<!-- SurveysList Feature -->
<ActivationDependency FeatureId="00BFEA71-A83E-497E-9BA0-7A5C597D0107" />
<!-- TasksList Feature -->
<ActivationDependency FeatureId="00BFEA71-C796-4402-9F2F-0EB9A6E71B18" />
<!-- WebPageLibrary Feature -->
<ActivationDependency FeatureId="00BFEA71-2D77-4A75-9FCA-76516689E21A" />
<!-- WorkflowProcessLibrary Feature -->
<ActivationDependency FeatureId="00BFEA71-4EA5-48D4-A4AD-305CF7030140" />
<!-- WorkflowHistoryList Feature -->
<ActivationDependency FeatureId="00BFEA71-1E1D-4562-B56A-F05371BB0115" />
<!-- XmlFormLibrary Feature -->
</ActivationDependencies>
</Feature>

No comments:

Post a Comment