Debugging Feature Installed Events
The commands for installing the features are part of the deployment process in Visual Studio. There are no flags or properties that you can set to debug this event in the Feature Receiver. In this recipe, we will guide you through the step-by-step process to accomplish this task.
Getting ready
You should have successfully completed Debugging 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.
Retract the solution if it was already deployed to a site.
Uncomment the FeatureInstalled method and press F9 to put in a break point.
Build the solution and package it.
From the command prompt use
stsadm
to add solution to solution store and deploy it as described in the recipe Deploying the Event Receivers. Follow the steps 8 and 9 in that recipe to deploy the solution.In the Visual Studio, go to project properties from menu Project | FeatureEventReceiver Properties.
In the Debug tab, set the external program to
Program
Files\Common
Files\Microsoft
Shared\Web
Server
Extensions\14\BIN\STSADM.exe
.Enter the command line arguments in the same tab as follows:
-o installfeature –name FeatureEventReceiver_Feature1 –force
Your debug tab should be similar to the one shown in the following screenshot:
In the window, open the SharePoint tab. Create a new Active Deployment Configuration and name it Empty Configuration as shown here and click OK.
Select the new configuration in the Active Deployment Configuration drop-down.
When you press F5, the debugger stops at the break point on
FeatureInstalled
method as shown in the following screenshot:
How it works...
In here, we
are manually attaching an external process to the Visual Studio debugger. In our case, STSADM.exe
is our external program. We did the preliminary work of adding the solution to the solution store and deploying the solution. We bypassed the entire deployment process that Visual Studio uses, so we can debug our Feature Receiver.
By default, Visual Studio provides two configurations: the Default configuration and the No Activation configuration. You cannot edit those configurations. None of these configurations are good for our purpose here. What we needed was a configuration that just deploys the solution without installing it. So we created an empty configuration and resorted to a manual process to debug this solution.
There's more...
Use the same process as used previously to debug the uninstalled event in the Feature Receiver. In step 8, substitute command line arguments as follows:
-o uninstallfeature –filename FeatureEventReceiver_Feature1\Feature.xml
See also
Debugging a Feature Receiver recipe