In a recent project, had to create a feature that provisions a bunch of Lists, Libraries, and Pages with custom web parts. Those custom web parts also deployed as feature-based solutions. So the requirement is: Activate the features which bring the custom web parts first and then activate the feature which creates the pages with custom web parts.
Problem: If the user tries to activate the Main feature- which creates web part pages with custom web parts, without activating a feature that brings the custom web part: Boom – Error!
How to Create Dependent Features in SharePoint?
Feature Activation dependency! How to implement? Simple! Just include the <ActivationDependencies> in Feature.xml
<?xml version="1.0" encoding="utf-8"?> <Feature Id="2cec1d22-290f-41b2-a14b-164a82d43b04" Title="Crescent Project Site Template" Description="Feature for Crescent project site Template" Version="220.127.116.11" Hidden="FALSE" Scope="Web" > <!--Set the activation dependency for Custom web parts feature --> <ActivationDependencies> <ActivationDependency FeatureId="GUID-OF-THE-DEPENDENT-FEATURE"/> </ActivationDependencies> <ElementManifests> <ElementManifest Location="elements.xml"/> </ElementManifests> </Feature>
Important: If a dependent feature is hidden, then it will be activated automatically when we activate the parent feature. If not, SharePoint will prompt the “Required Feature” page, instructing to activate the dependent feature first. We can’t have <ActivationDependencies> In a Parent feature which has Hidden=TRUE attribute.
Another frequent use of Feature Activation Dependency is: Page layouts!
Say, We’ve one Feature for Page Layouts and another for Custom content types. Custom Content types are the base for Page layouts (In another words, Page layout fields are from Custom content type). So we need Feature Activation Dependency here as well.