5
  1. I created a empty project
  2. added module
  3. copy onet.xml and default.aspx from layout/template/sts directory to my project and added to my project
  4. Ran F-5 to debug and it seems to be working
  5. Now I need to add some some on feature activation. I added a sample to code to add a list based on type 100 (object model , c#)
  6. After creating a site (web to be exact) I dont see the sample list that I asked feature activation to create.

What am I doing wrong? (Its a sandbox solution)

Anders Rask
  • 17,949
  • 3
  • 38
  • 71
Roxanne
  • 401
  • 1
  • 11
  • 19

4 Answers4

3

Hmm just to be clear, you cannot create custom site definitions as sandboxed solutions. If this must be a sandboxed solution you should instead create a custom web template. Read thhis guide by Vesa

Glorfindel
  • 1,050
  • 1
  • 11
  • 17
Anders Rask
  • 17,949
  • 3
  • 38
  • 71
  • @Anders: I am doing custom web template. Basically, I want to run some code when a sub-site is provisioned based on this template. I put the code on featureactivated event of the site feature and it did not fire when I create a sub-site. I then added another feature within the same project and scoped to web and put the event receiver code on feature's activated area. Still does not work (i also put feature activation code in the onet.xml file). I need to create few list using object model when a sub site is create. What are my options? – Roxanne May 08 '11 at 18:10
  • Ok but you wrote "custom site definition", and thats something else entirely ;-) Site features are not activated when webs are created. In SP2007 they did, but that was a bug that is now fixed in SP2010. If the web scoped feature isnt activated when creating sub sites, you need to check for reasons for this in ULS log. Also check that your solutions are deployed without errors Get-SPSolution | Select-Object Name, LastOperationResult or check in CA. You write you put your feature in feature's activated area AND onet.xml. Not sure what you mean by that. You cannot staple features on web templ. – Anders Rask May 08 '11 at 22:06
  • To validate if your code is called or not, set a breakpoint in feature activated and attach worker process in Visual Studio. If breakpoint isnt hit, either feature isnt provisioned correctly (check in activated features for web) or code isnt updated in GAC. To fix this either do a full redeploy or use CKS:DEV to copy dll to GAC – Anders Rask May 08 '11 at 22:08
  • As wictor mentioned on your new Q, check that feature is added to the relevant scope. Web scoped goes in WebTemplates, site scoped goes in SiteTemplates – Anders Rask May 09 '11 at 06:22
  • @Anders: Yes sir I did put the feature that is scoped to web under the webTemplate section of the onet.xml file. I get an error when I do that. (The site template requires that the Feature [GUID] be installed in the farm or site collection. Unfortunately it's not possible to use Feature Stapling with Web Templates in SharePoint 2010. – Roxanne May 09 '11 at 10:56
  • this error is typically seen when a site scoped feature is re-installed and the site feature isnt re-enabled. Make sure all site scoped features are installed and activated on your site collection before adding new sub sites – Anders Rask May 09 '11 at 13:58
  • @Anders: Aren't the feature are automatically installed on the 14 hive since i have the feature set to farm scope. I only have 2 features (1 for farm and 1 for web). Do I need to add a 3rd empty feature scoped to Site. The 2nd feature which scoped to web was added to webfeature section of onet.xml and I got the same error. Anders, can I email you my solution so you can see what I am doing wrong. – Roxanne May 09 '11 at 14:10
3

I experienced a similar issue. Upon creation of a new site, the features included in the <WebFeatures> node of the ONet.xml were not activated upon site creation. When navigating to '/_layouts/ManageFeatures.aspx' these features would appear to be activated but their code would not run (no files were placed from modules, breakpoints set in event receivers would not be reached). I was able to resolve the issue by making a change in my Feature nodes. Originally the nodes I used were copied from an ONET extracted from a .wsp that had been generated using the 'Save Site as Template' feature. Those nodes looked like this:

<Feature ID="{5bd39d1e-9e39-4e4f-932c-eb393b5454a4}" Name="FeatureDefinition/5bd39d1e-9e39-4e4f-932c-eb393b5454a4" SourceVersion=0.0.0.0" />

When I modified the Node to resemble this:

<Feature ID="{5bd39d1e-9e39-4e4f-932c-eb393b5454a4}" />

The features activated as expected.

bhammond
  • 51
  • 1
  • I don't know why it works that way, but making this change actually made our feature receiver to be called. – jjczopek Feb 21 '15 at 11:11
2

If you added the code in a Feature Receiver, you need that Feature to be avtivated upon site creation.

Thus, you need to add an element inside the ONET.xml which references your Feature. Have a look and you'll see the other features there, referenced with GUIDs.

You need to find the GUID your feature has been assigned within visual studio, then add that GUID to the list of Feature Activations within the ONET.

James Love
  • 25,512
  • 2
  • 45
  • 77
  • Thank you james. Is it going in the site template block of the onet.xml? – Roxanne May 08 '11 at 00:07
  • I added reference to onet.xml for the feature
  • My feature is at site coll. level so it's failing when I provision a web
  • What are my options?

    – Roxanne May 08 '11 at 00:12
  • I added a second feature so I can target this feature for web, scope == web. but when I change the scope to web it also changes the other feature's scope to web. Damn it. I am so hating SP. – Roxanne May 08 '11 at 00:29
  • You'll need any and all features to be web scoped in a Web Template. – James Love May 09 '11 at 07:31
  • @James: Are you sure about all features to be web scoped. I download Vesa's article solution where he added 4 features and each is scope to different (farm, sc, web, etc.). http://blogs.msdn.com/b/vesku/archive/2010/10/14/sharepoint-2010-and-web-templates.aspx#stepbystep – Roxanne May 09 '11 at 11:00
  • Ah yes, forgot about that - you can use code like in that example to force activation of site features... – James Love May 09 '11 at 11:23