Debugging CRM Plugins is no longer difficult with Plug-in Profiler. Follow the steps below and try to debug a CRM plugin in your environment.
1.Build the Plug-in Registration tool according to the instructions in its Readme file. The tool can be found in the Tools\PluginRegistration folder of the SDK download.
Current version of the SDK is 5.0.10
2.Run the Plug-in Registration tool.
Run the Visual Studio solution of plugin registration tool or after build the solution, Run the “PluginRegistration.exe” under “\tools\pluginregistration\bin\Debug\” folder
3.Connect to a Microsoft Dynamics CRM server and organization. For more information on connecting to a server and organization, refer to the SDK topic: Walkthrough: Register a Plug-in Using the Plug-in Registration Tool.
4.Register a plug-in and step on the Microsoft Dynamics CRM server. Keep a copy of the debug compiled plug-in assembly on the computer where you are running the tool.
Although Released or Debug assembly has been registered with the PluginRegistration tool, here it needs Debug Compiled vesion of the assembly to be debug using plugin profiler.
5.In the tool’s main window, select Install Profiler. You will now see a Plug-in Profiler node in the list.
6.Select a plug-in step and click Profile to enable profiling.
7.Perform the operation in Microsoft Dynamics CRM that causes the plug-in to run. For example, if the step is configured for an update to an account, then update an account.
8.After the plug-in throws an exception and the Business Process Error dialog is displayed, click Download Log File and save this file. Alternately, if the plug-in does not throw an exception, click Stop Profiling.
9.In the Plug-in Registration tool, click Debug.
10.In the Debug Existing Plug-in dialog box, provide the location of the previously saved log file.
11.In Step #2, specify the location of the plug-in assembly.
12.Launch Visual Studio 2010 and attach the debugger to the PluginRegistration.exe process.
13.Set a breakpoint in the plug-in code.
14.Click Start Plug-in Execution in the Debug Existing Plug-in dialog box.
15.After a slight delay, the plug-in will execute using the same execution context that was passed to it by the Microsoft Dynamics CRM server and the debugger will stop execution on the breakpoint that you previously set.
16.Continue debugging the plug-in as you would normally do. Any traces that the plug-in outputs are shown in the Debug Existing Plug-in dialog box.
At this point, can alter the plug-in code, build it, re-attach the debugger to the PluginRegistration.exe process, and click Start Plug-in Execution to continue with your debugging session. While performing these operations, do not need to close the Debug Existing Plug-in form.
Do not need to re-deploy the plug-in to the Microsoft Dynamics CRM server until after fixing the code problem. This debugging scenario works even if an optimized version of the plug-in on the server and a debug version of the plug-in on the computer where debugging.