Feature Versioning and Upgrading in SharePoint 2010


Introduction:

In this article we will be seeing about feature versioning and upgrading in SharePoint 2010. Feature Versioning and upgrading is a new feature in SharePoint 2010. Whenever a feature is activated at a specified scope in SharePoint, a feature instance is created that is associated with the current version of that feature. If a new and higher version of the feature is deployed, SharePoint 2010 detects that the associated feature instance needs an upgrade. We can make use of Version attribute on the Feature element in SharePoint 2010.

Feshare1.gif

FeatureVersioningandUpgrade_0_0_0_0.wsp (Feature Version 0.0.0.0):

FeatureVersioningandUpgrade_0_0_0_0.wsp is a sandbox solution which will be deployed to the solution gallery in the SharePoint site. This has a feature, which will add a custom column (CustomField_0_0_0_0 to the site columns) on activation.

FeatureVersioningandUpgrade_1_0_0_0.wsp (Feature Version 1.0.0.0):

This will contain upgraded feature which will add CustomField_0_0_0_0 and CustomField_1_0_0_0.

Steps Involved:

  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select "Empty SharePoint Project" from the installed templates.
  • Enter the Name as "FeatureVersioningandUpgrade" and click on Ok.
  • Right click on the solution and click on "Add new item".
  • Select the "Empty Element" template from the installed templates and enter the name.
  • Click on Add.

    Feshare2.gif

  • Double click on Elements.xml.
  • Create a custom field of type text as shown in the following.

    Feshare3.gif
     
  • Rename the Feature and my entire solution looks like the following.

    Feshare4.gif
     
  • Double click on the feature and in the properties window, set the version as 0.0.0.0.

    Feshare5.gif
     
  • The items in the feature

    Feshare6.gif
     
  • Build the solution.
  • Right click on the solution, click on "Package".

    Feshare7.gif
     
  • Right click on the solution and click on "Open folder in Windows explorer".

    Feshare8.gif
     
  • Go to Bin folder => Debug => Rename FeatureVersioningandUpgrade.wsp as FeatureVersioningandUpgrade_0_0_0_0.wsp.
  • Go to the SharePoint Site => Site Actions => Site Settings => Galleries => Solutions.
  • In the ribbon interface go to Solutions tab => New group => Upload Document.
  • Upload the FeatureVersioningandUpgrade_0_0_0_0.wsp.
  • In the ECB menu, click on "Activate".
  • Go to Site Actions => Site Settings => Site Actions => Manage Site Features => Activate the feature "FeatureVersioningAndUpgrade Feature".
  • Go to Site Actions => Site Settings => Galleries => Site Columns.

    Feshare9.gif
     

Upgrade the feature:

Here I am going to upgrade the feature by adding one more custom field CustomField_1_0_0_0 and change the version from 0.0.0.0 to 1.0.0.0.

  • Right click on the solution and click on "Add new item".
  • Select the "Empty Element" template from the installed templates and enter the name.
  • Click on Add.
  • Double click on Elements.xml.
  • Create a custom field of type text as shown in the following.

    Feshare10.gif
     
  • Double click on the feature and in the properties window, set the version as 1.0.0.0.
  • Double click on Versioning and Upgrade feature.Template.xml.
  • Add the following

    Feshare11.gif
     
  • Right click on the solution, click on "Package".
  • Right click on the solution and click on "Open folder in Windows explorer".
  • Go to Bin folder => Debug => Rename FeatureVersioningandUpgrade.wsp as FeatureVersioningandUpgrade_1_0_0_0.wsp.
  • Go to the SharePoint Site => Site Actions => Site Settings => Galleries => Solutions.
  • In the ribbon interface go to Solutions tab => New group => Upload Document.
  • Upload the FeatureVersioningandUpgrade_1_0_0_0.wsp.
  • In the ECB menu, you could see a new option "Upgrade".

    Feshare12.gif
     
  • Click on "Upgrade".

    Feshare13.gif
     
  • Go to Site Actions => Site Settings => Site Actions => Manage Site Features => Deactivate the feature "FeatureVersioningAndUpgrade Feature" and activate it.
  • Go to Site Actions => Site Settings => Galleries => Site Columns.
  • You could see two custom columns as shown in the following.

    Feshare14.gif