Tuesday 6 July 2010

Feature upgrade (part 2) – a sample to play with

In this article series:

  1. Feature upgrade (part 1) – fundamentals
  2. Feature upgrade (part 2) – a sample to play with (this article)
  3. Feature upgrade (part 3) – introducing SPFeatureUpgrade kit
  4. Feature upgrade (part 4) – advanced scenarios
  5. Feature upgrade (part 5) – using PowerShell to upgrade Features

In my last post I covered some fundamental aspects of SharePoint 2010’s Feature upgrade framework, and covered concepts such as upgrading Features using pure XML (ApplyElementManifests, AddContentTypeField) or shelling out to code (CustomUpgradeAction) to perform the necessary steps. For some reason it feels like Feature upgrade is one of those areas which is slightly harder to get up and running with, possibly because some XML will need to be cranked for some steps, or maybe because coming up with life-like upgrade scenarios with realistic artifacts takes some effort in itself. So, I thought it might be useful if I made available a sample I’ve been using (e.g. in my ALM talks and book chapter) for folks to download and use, in the hope that developers interested in seeing this stuff for themselves might have less work to do.

The sample

In addition to providing the source/XML files, I spent some time documenting the exact steps to go through when using the files to ‘execute’ my Feature upgrade scenarios. There’s a 3 page Word document which walks you through the upgrade steps, meaning the sample is effectively a “lab” of the type you might do on a training course:

 FeatureUpgradeSample_Doc

Similarly, the files provided cover all the different “states” in the process so you can just copy and paste the bits as you go:

FeatureUpgradeSample_Files

The upgrade examples

I came up with the following upgrade scenarios for the sample:

  • Upgrade iteration 1 - using ApplyElementManifests and AddContentTypeField to add new fields to a content type and push down to lists using it.
  • Upgrade iteration 2 – using CustomUpgradeAction/FeatureUpgrading to pseudo-upgrade a Text field to a Note field, by provisioning a new Note field/running code to iterate list items/copy data from old field to new/mark old field as hidden. (This scenario illustrates that many upgrades require code.)

The link

Download the files from http://sites.google.com/site/sharepointchris/sp2010_featureupgradesample

Summary

Feature upgrade is a slightly complex area, and I’m providing a sample that might help if this is an area of SharePoint 2010 you want to look more closely at. I’ve tested the documentation/files, but if anyone uses the sample and hits an issue, feel free to leave a comment here and I’ll do my best to help. The book chapter I wrote contains a rendition of this sample (along with much wider Application Lifecycle Management coverage, as you’d expect), but I thought it would be good to publish it to a wider audience.

7 comments:

Anna said...

Hi Chris,
I'm trying to run your sample solution and running into a problem. At the site collection level I only see the "Adventure Works Tourist Activities (Web)" feature and no site feature, so cannot activate the web feature on the subsites level as it depends on the (Site) feature which is not in the list and therefore I can't get it activated. Otherwise the deployment is smooth and uneventful, Im not sure wha'ts going wrong there. Any advice would be greatly appreciated.

Chris O'Brien said...

Hi Anna,

I just downloaded the sample and deployed to a new machine/web application. Everything went fine and the site collection Feature was there. I used the included helper script to activate the Features across the webs I created, but doing it manually through the UI should also be fine.

Could it be that my instructions had an error/weren't 100% clear instead? Does it happen if you try it again on a fresh site collection?

Any more information you can give might help me to help further.

Thanks,

Chris.

Anonymous said...

Hi Chris,
It was my mistake, I misunderstood the Sharepoint feature activation process and tried to activate the site - scoped part using the same "Manage site features" page while I should have been using "Site collection features" page.
I must say your feature upgrading explanation and sample are excellent, thank you for putting it all together.
Anna

Chris O'Brien said...

@Anna,

Great, no problem at all :)

Chris.

Jeremy Hancock said...

This is excellent Chris! Thanks for taking the time to put this together.

James Grizzle said...

Thank you so much for putting this together. You are the man!

Vaqar Hyder said...

Works like a charm Thanks Chris for this awesome post. Just for somebody who is looking fo scripts


Add-PSSnapin Microsoft.Sharepoint.Powershell –EA 0
update-spsolution -identity "AdventureWorks.CustomLists.wsp" -literalpath "\bin\Debug\AdventureWorks.CustomLists.wsp" -GACDeployment


$id = new-object System.Guid("")
$site = Get-SPSite "WebURL"
$feature = $site.Features[$id]
$feature.Upgrade($false)