How to: Add Elements to an Existing Feature
Applies to: SharePoint Foundation 2010
A basic Feature upgrade scenario is likely to include the steps listed in the following procedure, where new elements are added to an existing Feature.
Adding new elements to an existing Feature
Add a Version attribute to Feature.xml, if it does not already have one, and set it to a likely value, for example, Version="184.108.40.206" if the existing version is 220.127.116.11. If you do not increase the version number, Feature upgrade code will not be called.
Add an <UpgradeActions> section to the Feature.xml file.
Create a new Elements.xml file that contains all the new elements that you are adding to the Feature, and give it a unique name, for example, Elements2.xml.
Reference the Elements2.xml file in both the main <ElementManifests> section and the <ApplyElementManifests> section within the <UpgradeActions> section, as shown in the following example.
<Feature Id="712224F9-6708-4965-A18C-B73CA86AEFCA" Title="MyCoolFeature" Description="My cool feature." Version="18.104.22.168" Scope="Site" Hidden="FALSE" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests> <ElementManifest Location="Elements.xml" /> <ElementManifest Location="Elements2.xml" /> </ElementManifests> <UpgradeActions <VersionRange EndVersion="22.214.171.124"> <ApplyElementManifests> <ElementManifest Location="Elements2.xml" /> </ApplyElementManifests> </VersionRange> </UpgradeActions> </Feature>
When you activate the version "2" Feature, all elements in both the Elements.xml and Elements2.xml files will be provisioned. When you run upgrade on the server farm, the Feature upgrade infrastructure queries for all instances of your Feature that have a version number lower than version 126.96.36.199; and all elements in the Elements2.xml file will be incrementally provisioned for the existing version "1" Feature instances. If no errors occur, the Feature version number is updated in the database. If an error occurs while upgrading a particular instance of the version "1" Feature, that Feature instance is skipped over and the version number is not updated in the database. Subsequent farm upgrades will detect that the Feature instance has not been upgraded and will try to upgrade it again.