Question

In my Visual Studio 2010 SharePoint Project

I have a single SPItemEventReceiver that is contained in its own Elements.xml

I have 2 site collection features that are mutually exclusive they are never both activated on the same site collection.

I want to use the SPItemEventReceiver in them both.

I found that I can add the element.xml for my event receiver into both site collection features.

This seems to work but studio reports a warning.

The Project Item "MyItemEventReceiver" is included in the following Features: SiteFeature1, SiteFeature2

I cannot find any documentation on this warning or the possible side effects of this configuration.

What is the recommended way to share an SPItemEventReceiver between multiple features?

Was it helpful?

Solution

If this was VS2008, I'd create my receiver class in my project (standalone .cs file) that inherits from the right class and implements whatever it needs to do, and just wire up the two separate Elements.xml files from the two features to use the class by assigning the correct ReceiverAssembly and ReceiverClass properties.

You can probably do something similar with VS2010, but making using of the Feature merge files.

OTHER TIPS

It's a warning. It's simply there in case you didn't mean to have this configuration. i.e. you've added to the feature you want it in but didn't remove it from the feature it got added too by default.
I've successfully deployed and used solutions that gave this warning while packaging
The solution won't let you package if you're going to have two elements that wind up deploying to the same physical file location so I'd say in this instance you are safe to ignore the warning this time

I would suggest you try building the receiver as a separate project item. That should then get deployed with the solution package and can be added to both the features.

Not to incite a war here, but... Use WSPBuilder?

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top