Answered by:
Feature Stapling in SharePoint 2010 Web Templates

Question
-
Hi All
We have a new requirement where we have to staple a number of features to a custom web templates. Now when we try to staple the features to the custom web template, they are not getting reflected in the custom web templates.
Is feature stapling allowed in custom Web Templates? Could someone help out in this regard.
Thanks
- Sridhar Please visit my blog http://sharepointschool.wordpress.com/ for getting started with SharePointTuesday, September 28, 2010 2:40 PM
Answers
-
Here's some additional information and solutions for the requested customizations. Since we are talking BPOS deployment, site definitions are not and won't be supported due obvious reasons with the upgradability, even though "minimal site definition" approach would be taken.
The proper solution for sandbox and also full trust solutions is to use the new WebTemplate feature element, which is completely supported to be used also in BPOS scenarios and does not require any files to be deployed to file system. This is definitely the recommended approach for professional developers in SharePoint 2010 development.
Even though WebTemplate has been mostly visible for Sandbox solutions, it's completely supported to be used in full trust solution, since it provides huge advantages in sense of maintainability and upgradability of the custom solution. It's still true that feature stapling is not supported for WebTemplate, but there's actually no reason to use feature stapling, since you can as easily modify the WebTemplate onet.xml and deploy a new version of the feature. This is valid and supported for WebTemplate, but not for site definition due the technical solution in background.
There few slides and demo available in the following video. Even though in the demo case we deploy sandbox solution, like it's mentioned in the slides, WebTemplate is feature schema element available also as full trust solution.
· http://msdn.microsoft.com/en-us/sharepoint/ff420379.aspx#lesson1
We are currently working to release more information on the WebTemplate capabilities, since the current documentation is not that comprehensive and this obviously has caused lot of confusing concerning the guidance given.
Best regards,
Vesa Juvonen, Principal Consultant, Microsoft Consulting Services
Microsoft Certified Master for SharePoint 2007 & 2010- Proposed as answer by Vesa JuvonenMicrosoft employee Friday, October 1, 2010 6:16 AM
- Marked as answer by Wayne Fan Friday, October 1, 2010 6:21 AM
Thursday, September 30, 2010 10:47 AM -
Yeh sorry ... I was thinking most of SharePoint 2007.
In SharePoint 2010 using the "Save Site as Template" creates a WSP Package and installs the Site Definition using the new <WebTemplate> feature which is installed into the Sandbox.
You CANNOT use Feature Stapling on <WebTemplate> deployed Sites. It is not supported.
The recommended approach for professional development in SharePoint is to create your own WSP package with a Site Definition using WEBTEMP.XML files and an ONET.xml.
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.com- Proposed as answer by Martin Hatch Tuesday, September 28, 2010 4:06 PM
- Marked as answer by Wayne Fan Friday, October 1, 2010 6:21 AM
Tuesday, September 28, 2010 3:59 PM -
Feature stapling replies on using the Template Name, combined with the Configuration Id value, as defined the WEBTEMP*.XML files (located at ..\14\Template\1033\XML).
they follow the format of <WebTemplate>#<ConfigurationID>.
For example, the "Team Site" is located in WEBTEMP.XML, and has a Web Template name of "STS" and a Configuration ID of "0".
Therefore the value for stapling is "STS#0".
Make sure your feature stapler is correctly referencing the correct template / configuration value.
Note - If you have used "Save Site As Template" then it will NOT create a new Template / Configuration .. and will instead use the configuration value of the ORIGINAL site used to create the template.
As a result, you cannot Staple features to a template created in this manner (or at least .. not without stapling it to the original web template of the source site).
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.com- Proposed as answer by Becky Bertram Tuesday, September 28, 2010 3:35 PM
- Marked as answer by Wayne Fan Friday, October 1, 2010 6:21 AM
Tuesday, September 28, 2010 3:13 PM
All replies
-
Feature stapling replies on using the Template Name, combined with the Configuration Id value, as defined the WEBTEMP*.XML files (located at ..\14\Template\1033\XML).
they follow the format of <WebTemplate>#<ConfigurationID>.
For example, the "Team Site" is located in WEBTEMP.XML, and has a Web Template name of "STS" and a Configuration ID of "0".
Therefore the value for stapling is "STS#0".
Make sure your feature stapler is correctly referencing the correct template / configuration value.
Note - If you have used "Save Site As Template" then it will NOT create a new Template / Configuration .. and will instead use the configuration value of the ORIGINAL site used to create the template.
As a result, you cannot Staple features to a template created in this manner (or at least .. not without stapling it to the original web template of the source site).
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.com- Proposed as answer by Becky Bertram Tuesday, September 28, 2010 3:35 PM
- Marked as answer by Wayne Fan Friday, October 1, 2010 6:21 AM
Tuesday, September 28, 2010 3:13 PM -
Hi Martin,
Thanks for your response.The approach you have mentioned will work fine for Stapling of features to a Site Definition.My Issue is I have to staple the feature to a Custom Web Template and tried the following approaches but still unable to .
Approach 1:
Stapling the Features to the Base Site Definition:
1) Creating a wsp that does the Stapling of Features to the BASE Site Definition (say for e.g.: STS#0)
2) Successfully Deployed the wsp (Now the Feature Stapling is done to the site definition STS#0)
3) Create a custom web template with base template as STS#0
4) Deploy the web template.
Result: The Features that are stapled to the site definition STS#0 are Not getting reflected in the custom Web Template.
Approach 2:
Stapling the Features to the Custom WebTemplate:
1) Creating a wsp that does the Stapling of Features to the Custom WebTemplate
2) Code Snippet used for stapling the feature to a Custom Web Template :
a. <FeatureSiteTemplateAssociation Id="7bf8afb6-57dd-408d-b7c5-fea4b861b3cc" TemplateName="<{FeatureID of Web Template}#Template Name>" />
b. <FeatureSiteTemplateAssociation Id="7bf8afb6-57dd-408d-b7c5-fea4b861b3cc" TemplateName="<Template Name>" />
c. <FeatureSiteTemplateAssociation Id="7bf8afb6-57dd-408d-b7c5-fea4b861b3cc" TemplateName="<{ FeatureID of Web Template }>" />
3) Successfully Deployed the wsp
Result: The Features that are stapled are Not getting reflected in the custom Web Template
Note: In approach 2 the WebTemplate is already deployed.Trying to staple the feature to the webtemplate that is already deployed
Chetan Sharma please visit my blog http://SharepointSchool.WordPress.Com for getting started with Sharepoint 2010Tuesday, September 28, 2010 3:41 PM -
Sorry .. when you say "custom web template" do you mean using the "Save Site As Template" function?
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.comTuesday, September 28, 2010 3:46 PM -
No ... i am creating a webtemplate using a <WebTemplate> element which is newly introduced in Sharepoint 2010.I am making use of the OOTB Team site definition.Below is the code snippet of how i have created a custom web template from scratch.
<?
xml version="1.0" encoding="utf-8"?>
<
Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<
WebTemplate Name="CustomWebTemplateDemo"
Title="CustomWebTemplateDemo"
Description="CustomWebTemplateDemo"
BaseTemplateID="1"
BaseTemplateName="STS"
BaseConfigurationID="0"
DisplayCategory="ShellTemplates"></WebTemplate></Elements>
For furthur details of how i have created a web template is discussed in detail at the URL mentioned below.
http://sharepointschool.wordpress.com/2010/09/20/web-templates/
Thanks for your reply Martin...
Chetan Sharma please visit my blog http://SharepointSchool.WordPress.Com for getting started with Sharepoint 2010Tuesday, September 28, 2010 3:58 PM -
Yeh sorry ... I was thinking most of SharePoint 2007.
In SharePoint 2010 using the "Save Site as Template" creates a WSP Package and installs the Site Definition using the new <WebTemplate> feature which is installed into the Sandbox.
You CANNOT use Feature Stapling on <WebTemplate> deployed Sites. It is not supported.
The recommended approach for professional development in SharePoint is to create your own WSP package with a Site Definition using WEBTEMP.XML files and an ONET.xml.
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.com- Proposed as answer by Martin Hatch Tuesday, September 28, 2010 4:06 PM
- Marked as answer by Wayne Fan Friday, October 1, 2010 6:21 AM
Tuesday, September 28, 2010 3:59 PM -
Thanks Martin.
We have this requirement for a Sharepoint Online 2010 (BPOS-D) where SiteDefinitions are strictly not allowed.So we came up with an approach of WebTemplates. Now we also have number of features that are to be stapled.Now could you suggest the approach where we can achieve this.
Thanks for your Reply Martin
Chetan Sharma please visit my blog http://SharepointSchool.WordPress.Com for getting started with Sharepoint 2010Tuesday, September 28, 2010 4:04 PM -
Yes .. you cannot staple features to a <WebTemplate> created through a feature.
The <WebTemplate> is specifically designed for Sandbox Solutions (designed for secured site collections, where you cannot deploy files to the file-system).
As a result, it does not support stapling.
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.comTuesday, September 28, 2010 4:06 PM -
Hi Martin,
As explained above, we have tried all possible approaches. But none of them seem to work. And we are deploying the custom web template as a farm feature rather than a site feature to meet the restrictions in Sharepoint online.
So if stapling is not allowed, then we have to look for other alternatives for creation of new sites :(, which is again a time taking process.
- Sridhar Please visit my blog for getting started with SharePointTuesday, September 28, 2010 4:10 PM -
If you have control over the onet.xml .. why not just add the Feature references manually?
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.comTuesday, September 28, 2010 4:11 PM -
I mean ... I usually use Feature Stapling so that I can modify OOB site definitions (like MySites) which DO have a web template / config ID that you can reference.
Feature Stapling makes the upgrade process easier (because you don't have to modify the onet.xml) but there are still patterns and practices for not using Stapling at all (____ ... we all had to do that back in SP 2003 .. before "stapling" and "features" existed).
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.comTuesday, September 28, 2010 4:13 PM -
Thanks Martin.
We have this requirement for a Sharepoint Online 2010 (BPOS-D) where SiteDefinitions are strictly not allowed.So we came up with an approach of WebTemplates. Now we also have number of features that are to be stapled.Now could you suggest the approach where we can achieve this.
Thanks for your Reply Martin
Chetan Sharma please visit my blog http://SharepointSchool.WordPress.Com for getting started with Sharepoint 2010
I assume that wouldn't tbe same "Wave 14" BPOS which is strictly under NDA?Regarding your problem .. WHY do you need to use stapling?
Why don't you just attach the Features directly to your Web Templates by modifying the onet.xml ?
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.comWednesday, September 29, 2010 7:41 AM -
Yes Martin I agree with your approach. While deploying a custom web template what ever features needsd to be activated or attached those we can always refer in the ONET.xml. But after deployment if any more features needs to get attached to the web template,it's not a best practice to always change the web template right?.So this is where we got stuck.Now Feature Stapling cannot be done to the CustomeWebTemplate so this is ruled out.So could you suggest us with the best practice of getting this done.
Thanks a lot for your quick Response.
Chetan Sharma please visit my blog http://SharepointSchool.WordPress.Com for getting started with Sharepoint 2010Wednesday, September 29, 2010 7:56 AM -
Good question .. and I have to admit I'm struggling to find information about this.
There is reference to an Upgrade Definition which contains a <WebTemplate> element, so it looks like there is support for Feature Upgrade for <WebTemplate> elements.
http://msdn.microsoft.com/en-us/library/aa543624.aspx
<WebTemplate
BeginFromSchemaVersion = "Integer"
EndFromSchemaVersion = "Integer"
FromProductVersion = "Integer"
ID = "Integer"
LocaleId = "Integer"
RemoveSiteExternalSecurityProvider = "true | "false"
ToSchemaVersion = "Integer">
...
<Lists>
...
</Lists>
<Files>
...
</Files>
<AppliedWebFeatures>
...
</AppliedWebFeatures>
</WebTemplate>Not sure if this is exactly what you're looking for, but should give you a good start
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.comWednesday, September 29, 2010 8:08 AM -
Here's some additional information and solutions for the requested customizations. Since we are talking BPOS deployment, site definitions are not and won't be supported due obvious reasons with the upgradability, even though "minimal site definition" approach would be taken.
The proper solution for sandbox and also full trust solutions is to use the new WebTemplate feature element, which is completely supported to be used also in BPOS scenarios and does not require any files to be deployed to file system. This is definitely the recommended approach for professional developers in SharePoint 2010 development.
Even though WebTemplate has been mostly visible for Sandbox solutions, it's completely supported to be used in full trust solution, since it provides huge advantages in sense of maintainability and upgradability of the custom solution. It's still true that feature stapling is not supported for WebTemplate, but there's actually no reason to use feature stapling, since you can as easily modify the WebTemplate onet.xml and deploy a new version of the feature. This is valid and supported for WebTemplate, but not for site definition due the technical solution in background.
There few slides and demo available in the following video. Even though in the demo case we deploy sandbox solution, like it's mentioned in the slides, WebTemplate is feature schema element available also as full trust solution.
· http://msdn.microsoft.com/en-us/sharepoint/ff420379.aspx#lesson1
We are currently working to release more information on the WebTemplate capabilities, since the current documentation is not that comprehensive and this obviously has caused lot of confusing concerning the guidance given.
Best regards,
Vesa Juvonen, Principal Consultant, Microsoft Consulting Services
Microsoft Certified Master for SharePoint 2007 & 2010- Proposed as answer by Vesa JuvonenMicrosoft employee Friday, October 1, 2010 6:16 AM
- Marked as answer by Wayne Fan Friday, October 1, 2010 6:21 AM
Thursday, September 30, 2010 10:47 AM -
There's now more guidance available on the web template topic. Subject is covered quite detailed in following blog post from multiple angles. This information should have been available sooner, but it's better late than never.
Best regards,
Vesa Juvonen, Principal Consultant, Microsoft Consulting Services
Microsoft Certified Master for SharePoint 2007 & 2010Friday, October 15, 2010 6:43 AM -
Dear Vesa
You stated "This is valid and supported for WebTemplate, but not for site definition due the technical solution in background"
Is it not supported to upgrade a onet.xml file of a custom site definition?
Tuesday, April 19, 2011 8:02 PM