Feature not automatically activating in some site collections

I am working on a dev site with no data, it's strictly for design purposes. I have a wsp that contains a feature scoped at "web". The feature contains a list instance. so whenever I deactivate and then try to reactivate, even via code, I run into an error because that list name already exists. I have three site collections, one at the root and two in /sites. My debug env is set to the root url. So to cure this problem, I have added a deletion and creation of each of these three sites in my predeployment so that activation can work. I also am using the default activation settings which pretty much checks for everything and more specifically, activates the features. This only works for the root level site, and the other two sites show the feature fine, but they are not being automatically activated like the root site feature instance was. When i manually activate these two feature instances, it works fine.

My understanding is that when you scope a solution and it's features to "web", which I have done it does the same thing for all webs on all site collections. So theoretically, I should expect to see that the feature was activated at the site features level (not site collection features level) of all site collections. it shows up at the site features level (not site collection features level) ready to be activated when they should be activated already.

Is it that the default deployment has something to do with my dev settings where it only deploys to the root url? So since I use a predeployment command script to delete and recreate all three sites, is it possible that these other two sites are merely picking up the features scoped to "web" upon creation, but the actual activation part of the deployment was never run on them and instead just the root site collection? If so, why? I think it's very important that I understand this thoroughly before I go anywhere near a production env.

Who is Participating?
I am hoping you are directly deploying the solution from the development tool which has the URL set to your root level site collection.
when you deploy then the solutions or features will be deployed to the URL you have specified in the Dev tool site URL place or target URL.

you can either write another piece of code on web adding or web provisioning events and have your feature activated here.

if i am not mistaken here do you have any code that activated your feature when a site or web is created or provisioned or feature staples with the site definitions.

when you deploy through VISUAL studio if the solution is set to be activate when deployed in properties then it will automatically activate all the features present in the solution to the target URL in your case( your Dev URL), but it doesn't activate it in another Site collection unless you write a code to activate the feature whenever a new web is added or created.
BobHavertyComhAuthor Commented:
I understand and agree totally with what you explained. Thank you. In fact, I even tried to activate from stsadm, and sure enough, it needs a specific url and giving it the root site collection address only activated it there, then giving it the other addresses in separate activation commands activated them there. So it can definitely only activate one at a time, even though it can install to all of them, so it sounds like they did this on purpose.

The problem i have is that the sites are being deleted and re-created during pre-deployment, so it seems like that site creation event code is going to be looking to activate a feature that hasn't been deployed yet.
you are adding the feature and make it available in web scope but you haven't written to automatically activate the feature.
unless you do it manually either using command or through UI it will never be activated.
for root site the Dev tool does that in behalf of you.
so the best idea is write code in either of events in web level and have the code to activate the feature if not activated.

here is the list of web events you can write::
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

BobHavertyComhAuthor Commented:
Hi kukdai. Even if I code the web creation events rather than the site creation events, isn't the code going to attempt the activation before the deployment of the feature it is activating and therefore fail? For reasons mentioned above, I need to wipe the site collection out and recreate it during pre-deployment, and even if I did this with a site (web) where only the webs get deleted and recreated, not the site collection, it would still be trying to activate something that hasn't deployed yet and won't until the deployment stage after the creation event has happened.
BobHavertyComhAuthor Commented:
Actually, what I've done is to take activation out of my deployment altogether and added post deployment commands to activate the feature for each site collection url. Worked perfectly, but it means I have to maintain a post deployment list of site collections. Maybe later, I'll attempt a powershell script that walks through all site collections in the farm and activates this feature and see if I can merely copy and paste it into the VS post deployment section of the project properties.
your solutions will remain there doesn't matter you delete or create site collection.
if you delete a site collection it doesn't mean it will delete the feature unless you write a code in site or web deleting event.
in your own solutions of you have a feature then try adding some event receiver in the feature like activated so which will activate another feature the one you want before activating itself.

how does your solutions works.
usually none of the SharePoint solutions works automatically. you are deploying directly from the Dev tool doesn't means that the solutions will automatically run. it is automatically activated becoz the Dev tool runs the command to activate in the site URL mentioned.
your solutions doesn't have anything to activate it automatically.

so first of all.
1. check the Main solutions which creates and deletes the site collection. how does this solutions is run do you have any feature to activate and then it executes. i am hoping you will not have a Dev tool in Prod do deploy the solution you have to write the command manually to add the solutions to prod.

2. if you have any feature in the parent solution then in that solution you can activate the feature after the codes that creates  the sites.

you can use feature stapling as well where features are dependent to each other.
or you can write a command once your site collection code is completed iterate through all site collection and activate the feature.

there are various ways choice is yours how you like
BobHavertyComhAuthor Commented:
Hi kukdai, I enjoy your very thorough knowledge of the subject.

It seems to me that you are saying to not run anything during solution package deployment, using none of VS's auto deployment operations, and instead transfer all necessary deployment operations (retraction/addition/iisreset....) to an on creation event for a site or solution or feature. If so, in the case of a feature creation events, wouldn't I have to write event receiver code for every feature in the solution if the solution grows? Doesn't a VS solution package manage this better where it will act upon all features in the solution and isn't that an advantage to letting it do the deployment operations for you? You mentioned about running commands after all site creation event code has run, but aren't the commands i entered into my post deployment settings in the solution package already doing this for me? seems like it's the same exact thing except I don't have to bother with the command prompt.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.