Debugging a Feature Receiver
Debugging a Feature Receiver is a different process. It is not like debugging the List Item Event Receivers. As described in the previous recipe, Visual Studio does lots of work behind the scenes and so we are unable to hit the break points.
Apart from that, debugging Feature Receivers are dependent on events that we are trying to debug. In this recipe, we will follow through the process of debugging FeatureActivated
and FeatureDeactivating
events.
Getting ready
You should have successfully completed the Creating a Feature Receiver recipe.
How to do it...
Launch Visual Studio as an administrator and open the solution that was created in the previous recipe.
In the solution explorer, select the project and press F4 to bring open the project properties window.
Set the Active Deployment Configuration to No Activation as shown here:
Put break points on both
FeatureActivated
andFea
ture
Deactivating
methods and run the project.This will bring up the site in the default browser. Navigate to Site Actions | Site Settings | Site Actions | Manage site features. This should bring up the page as shown in the following screenshot and you should be able to see your
Feature
installed, but not activated.Clicking the Activate button should invoke the debugger now.
Similarly, clicking the Deactivate button should invoke the debugger to hit the break point on the
FeatureDeactivating
method.
How it works...
By default Visual Studio sets up for Activation of the features. This makes sense as all the different SharePoint projects make use of Features and for test purposes it is very necessary to activate it and execute the solution. So every time a developer creates a SharePoint project, they do not need to remember to set this flag.
This does create a problem for Feature Receivers though. Hence we set the flag to No Activation and there by Visual Studio just installs the solution without activating it.
There's more...
That's right, now we know how to debug Feature Receivers events like Feature Activated and Feature Deactivating. Is there a similar flag that we can set in Visual Studio to Debug Feature Installed and Feature Uninstalled? No, there are no flags that you can set to make debugger stop on the break points on Feature Installed and the Feature Uninstalling methods.
See also
Creating a Feature Receiver recipe
Debugging Feature Installed Events recipe