Sunday, June 14, 2015

How to remote debug Dynamics CRM plugins and workflow assemblies

1. Make sure you copy your plugin/workflow assembly (.dll) and .PDB files to the CRM server directory <crm-root>\Server\bin\assembly.
Typically, this is the folder ‘C:\Program Files\Microsoft CRM\server\bin\assembly
Important: if your assembly depends on other .dlls and they are not registered on the GAC in the CRM Server (or want to debug them also), copy them also to the same directory.
Note: if your assembly has already been deployed to that directory and need to update it, you may need to restart IIS in order to unlock it because it may be in use by the IIS process.
2. Register your assembly by selecting ‘on-disk deployment’ . This can be easily and intuitively done by using Plugin Registration Tool in CRM SDK.
3. Restart IIS on the CRM Server. Note that you may be need to do this before as mentioned above.
4. If not yet installed yet, you will need to install Visual Studio Remote Debugger component on the CRM Server.  For doing so:
a. Within the Visual Studio 2010/2008 installation media (or ISO image) go to ‘Remote Debugger folder’.
b. There you will find some setup files. Just double click the one that matches with your platform.
image
c. Setup starts…
image
d. Accept the licence terms..
image
e. Installation starts..
image
f. Once installation is completed, rebooting your machine will be required.
5. Now, let’s configure the Remote Debugger component by running the Visual Studio Remote Debugger Configuration Wizard.
a. So, go to Start->All Programs->Microsoft Visual Studio 2010/2008->Visual Studio 2010/2008 Remote Debugger Configuration Wizard as shown in the picture below.
image
b. Welcome screen shows up…
image
c. We can configure to run Remote Debugger as a service or a Windows application.
image
I recommend and chose the latter as its less invasive, less resource consuming and more secure because you explicitly start and stop this component. Moreover, by choosing the latter you can set up permissions and easily copy the server name for debugging purposes.
d. Set up options and permissions by clicking in Tools->Options:
image
e. Within Options Window, click on Permissions button to set up the users that will be allowed to remotely debug on the server:
image
You will be able to add administrators as well as other users belonging to the Debugger Users group.
Despite adding Everyone to this group and selecting it on this Windows is something not recommended for security reasons, it works fine and sometimes avoid problems that may occur in the middle while trying to debug (which usually responds to some urgent situation Smile).
d. Now, copy the exact server name string which is displayed on Options window.
image
This is very important as this is the string you will need to paste within your local Visual Studio in order to remotely connect to the CRM Server machine.
e. Press OK to accept options. A message telling that the service has been started should be displayed on the main Visual Studio Remote Debugging Monitor window.
6. Open your local Visual Studio and set up the breakpoint(s) you want to monitor in your plug-in / workflow activity classes. It could also be breakponts in one of the dependent assemblies (as far as .PDB file are deployed to <crm-root>\Server\bin\assembly)
7. Attach Visual Studio to CRM Server remote working process, that is, remote w3wp.exe service (in case of plugins) and Crmasyncservice.exe (in case of workflow activities).
    For doing so, press CTRL + ALT + P  or select  Debug->Attach to Process menu option…
8. Paste the server name string into the Qualifier field, as shown below:
image
9. Select the w3wp.exe and/or Crmasyncservice.exe process .
10. Run your tests (i.e. modifying/creating some entity in order to make the plug-in being triggered).

No comments:

Post a Comment

How to Deploy your API as a web app or API app

  Before you can call your custom API from a logic app workflow, deploy your API as a web app or API app to Azure App Service. To make your ...