While putting content types into their own features and using a solution to deploy them makes deployment much easier, you can get into a quagmire in a hurry as the number of content types grow in your solution. I recently worked on a solution that contained over a hundred content types. The site collection features gallery was many pages in length with each content type having its own line. You can further simplify your deployment efforts by setting activation dependencies, using hidden features, and auto activating features.
In this article, I will create a feature to activate the Character Sheet feature that I wrote in my previous posts and I will set it up in such a way that it will automatically activate the Character Sheet when it is activated. Further, I will set it so that it will activate automatically when the solution is deployed.
1. Create a parent content type called RPG_Content_Types
As with my previous example, this feature resides in its own folder in the features folder and it contains a feature.xml file; but this is the only file that it contains. The feature’s header looks the same as the previous feature; be sure to create a new feature id using the guid tool. With one exception, add the AutoActivateInCentralAdmin attribute to the header to activate this feature on deployment. Rather than an ElementManifests section; however, this one contains an ActivationDependencies section.
As with my previous example, this feature resides in its own folder in the features folder and it contains a feature.xml file; but this is the only file that it contains. The feature’s header looks the same as the previous feature; be sure to create a new feature id using the guid tool. With one exception, add the AutoActivateInCentralAdmin attribute to the header to activate this feature on deployment. Rather than an ElementManifests section; however, this one contains an ActivationDependencies section.
2. Set activation dependencies for the other features
Now we will add an activation dependencies section to the feature.xml that will require other features to be activated before this one can activate. The nifty thing about this is that if the features on which this one is dependent are hidden, then this one will activate those automatically.
Now we will add an activation dependencies section to the feature.xml that will require other features to be activated before this one can activate. The nifty thing about this is that if the features on which this one is dependent are hidden, then this one will activate those automatically.
3. Modify the other features to make them hidden
Open the Character Sheet feature and change the Hidden attribute from FALSE to TRUE.
Open the Character Sheet feature and change the Hidden attribute from FALSE to TRUE.
4. Add the new feature to the solution’s manifest
Add the new feature in exactly the same way as you did the Character Sheet feature.
Add the new feature in exactly the same way as you did the Character Sheet feature.
5. Add the feature to the ddf file
Finally, add a line to the ddf file that will include the new feature in the CAB output. As an additional step, you may want to change the wsp filename since this solution now contains more than just the CharacterSheet content type.
Finally, add a line to the ddf file that will include the new feature in the CAB output. As an additional step, you may want to change the wsp filename since this solution now contains more than just the CharacterSheet content type.
6. Redeploy the solution
Since I have expanded this solution to include more than one content type, I have renamed the wsp file to RPGContentTypes. So the first step is to go into Central Admin/Operations and click Solution Management. In there I retract and remove the old CharacterSheet.wsp solution. At the command line, run the make command to create a new wsp file and use stsadm -o addsolution to add the solution to your farm. Back on the farm, deploy the solution.
Since I have expanded this solution to include more than one content type, I have renamed the wsp file to RPGContentTypes. So the first step is to go into Central Admin/Operations and click Solution Management. In there I retract and remove the old CharacterSheet.wsp solution. At the command line, run the make command to create a new wsp file and use stsadm -o addsolution to add the solution to your farm. Back on the farm, deploy the solution.
7. Validate installation
The easiest way to validate the installation of your features is to check the content types gallery to see if your Character Sheet content type is available. Alternatively, you can look at your site collection features where you will see only the RPG_Content_Types feature. Since the Character Sheet is now hidden, the only way to see it is to use the object model to access the list (but that is a post for a different day).
Now you have a feature that can activate others at solution deployment time saving you the headache of managing feature installation and activations from the site settings or the command line. Even a batch file with all of the feature installation and activation commands isn’t as easy as this. Now you can add more content types to your solution and include them as activation dependencies. For example, I added a monster sheet content type in its own feature and added its feature id in the activation dependency section.