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
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:
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
Featureinstalled, 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
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.
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.