Debugging Plugins :
After a plugin has been registered properly in a development setting, generally
you want to work through debugging. Debugging a CRM on-premise solution
is similar to debugging any ASP.NET application. And it requires fewer steps than debugging CRM Online. Debugging Online can be more time-consuming and therefore requires more thought and care in development. The following sections outline how to debug in both environments.
Debugging CRM On-premise Solutions:
When debugging on-premise, you can use Visual Studio to attach to a process
and step through the code. The following steps are all that’s required:
1. Make sure that the DLL and PDB that are built with your Visual Studio
solution are current, and that the current builds of both are in the server/bin
folder of your on-premise CRM installation folder. You need to register the
plugins using the Plugin Registration tool prior to taking any further steps.
2. Click the Debug menu option in Visual Studio and select Attach to Process. You want to attach to all instances of w3wp.exe listed in the Available Processes panel.
Note When debugging workflow activities, you need to attach to the
CrmAsyncService process in the Available Processes panel (w3wp.exe is the
process to attach to for plugin debugging).
Note When debugging on a remote server, you need to use the Visual
Studio Remote Debugger and configure Visual Studio to connect to the target
machine.
Debugging CRM Online Plugins
CRM Online can’t be debugged in the same way as CRM on-premise because
there is no way to attach the Visual Studio environment directly to CRM Online.
Instead, you need to take several steps to allow for debugging. This section describes those steps.
Installing the Profiler
The first step to debugging in the CRM Online environment is to install the profiler.You do that by opening the Plugin Registration tool and connecting to the instance that has the plugin you want to debug. Click the Install Profiler button on the menu bar.
Note To uninstall the profiler, make sure you click the Uninstall Profiler button
in the Plugin Registration tool. If you simply unregister it (as you would anything else registered), you’ll leave a lot of pieces installed and will have some additional cleanup work to do.
Profiling a Step:
With the profiler installed, the next step is to right-click the step within a plugin
that you want to debug and select the Start Profiling option. In the Profiler Settings, you can set various properties. You can generally use the default settings here and simply click OK. Once a step has been configured with
the profiler. You can add profiling to as many steps as you need to
successfully debug your code.
Triggering the Profiler and Saving the Log File:
Now that the step is successfully profiled, you need to trigger the code behind
the step to execute. Go into the CRM Online front end and force the action to occur that will trigger the step (for example, if the step is on the loss of an opportunity,go into an opportunity and click Lost Opportunity). When the code is hit, an error similar to that shown in image will pop up. Click the Download Log File button and save it.
Debugging, Attaching, and Breakpoints:
Back in the Plugin Registration tool, click the Debug button (on the menu, next
to the Uninstall Profiler button). Set the Profile Location property to the local path where you downloaded the log file. The Assembly Location property should be the local path where the assembly DLL and PDB files are located. Make sure that this is the same build that the Visual Studio code you’ll be debugging is associated with.
Open your plugin code in Visual Studio and set breakpoints where appropriate.
You should start by putting a breakpoint on the first piece of code that will execute when triggered, so that you can ensure all your code is firing as expected.
Studio and select Attach to Process. In the Available Processes panel, highlight the pluginregistration.exe process and click the Attach button.
Finally, once everything is attached in Visual Studio, click the Start Execution
button in the Debug Existing Plug-in tool.You will now be able to step through your code.
No comments:
Post a Comment