Reputation: 4907
I have a wsp package that contains many features. Some of the features included in the wsp package depend on other features that are also in the wsp package.
In my case, 2 content types are created via features (Content Type A and Content Type B) and Content Type B inherits from Content Type A.
So obviously, the feature that contains the Content Type A (feature A) needs to be deployed before the feature that contains Content Type B (feature B).
Is there a way to make feature A deploy before feature B? Ideally, both features would be activated automatically through the onet.xml file and feature A would just be deployed before, but I have no idea how to do that...
I'm not necessarily looking for a solution that solves this particular problem, but I want to know is : How do you deal with features that depend on other features in a SharePoint project?
Thanks!
Upvotes: 3
Views: 534
Reputation: 1712
You can also create an event handler and activate the features in the order you want. I've found it always to be better to rely on doing things manually in code rather than using the xml files to do thing.
Take a look at SPWeb.Features and FeatureCollections.Add
Here is an example of how I coded this in my event handler
public void ActivateFeatures(SPFeatureReceiverProperties properties)
{
logger.Info("Creating content types");
// feature is scoped at Site, so the parent is type SPSite rather than SPWeb..
using (SPSite site = properties.Feature.Parent as SPSite)
{
SPWeb currentWeb = null;
if (site != null)
{
currentWeb = site.RootWeb;
}
else
{
currentWeb = properties.Feature.Parent as SPWeb;
}
using (currentWeb)
{
if (currentWeb == null) return;
try
{
currentWeb.Site.Features.Add(new Guid("01A27C0C-2E44-4298-A74F-8F50601A20B0")); // ctCategory
currentWeb.Site.Features.Add(new Guid("496DFE3E-A41E-46e8-B627-29775F376017")); // ctChapter
currentWeb.Site.Features.Add(new Guid("F2ECBD5A-4766-49bf-A158-62550661E141")); // ctChapterList
currentWeb.Site.Features.Add(new Guid("8C91646F-1466-49d7-BB53-B666F164AA96")); // ctComments
currentWeb.Site.Features.Add(new Guid("112E1564-FA1C-41fd-853A-F7569C555905")); // ctDocument
currentWeb.Site.Features.Add(new Guid("48BD5A07-8DD1-46ef-9F05-9824380BA26E")); // ctExternalReviewer
currentWeb.Site.Features.Add(new Guid("20553A8E-8272-400c-816D-6EE8E02F34E9")); // ctStandard
currentWeb.Site.Features.Add(new Guid("E84259BD-E4B3-465e-8928-1745F8760F2D")); // ctSuggestion
currentWeb.Site.Features.Add(new Guid("0B313654-D296-4bfa-8F21-E4FF33C1DD6C")); // ctTask
currentWeb.Site.Features.Add(new Guid("EFDA877B-B686-4954-9F1A-65ADB32B2E50")); // ctDepartment
currentWeb.Site.Features.Add(new Guid("4E4B984E-65E2-4601-A216-2C4D08AA97AE")); // ctInnerWork
currentWeb.Site.Features.Add(new Guid("4D85D4B9-1909-45cd-81C7-CDBB0874492F")); // ctOtherDocuments
logger.Info("Content types added successfully");
}
catch (Exception ex)
{
logger.Error("Could not in activate content types.", ex);
}
}
}
}
Upvotes: 4
Reputation: 28325
You can use the feature activation dependencies... feature.
<Feature Id="01c34560-6561-11dc-8314-0800200c9a66?
Title="Nice to know"
Description="This is a feature that adds a new sexy CSS"
Version="1.0.0.0?
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ActivationDependencies>
<ActivationDependency FeatureId="F6924D36-2FA8-4f0b-B16D-06B7250180FA"/>
</ActivationDependencies>
<ElementManifests>
<ElementManifest Location="ProvisionedFiles.xml"/>
</ElementManifests>
</Feature>
Take a look here for an overview.
Upvotes: 3
Reputation: 1520
You can use activation dependencies to associate features with one another. You use the
<ActivationDependencies>
<ActivationDependency>
xml elements in the feature file. You can read more about it here: http://msdn.microsoft.com/en-us/library/aa543162.aspx
Upvotes: 1