Guest Post: Three Top Tips for CRM 4.0 Plugin Development
Tip #1 Sign your assembly!
This is a step that's importance isn't made blatantly clear in the SDK documentation, but is absolutely key to the successful implementation of your plugin (and also makes a huge difference to debugging successfully as well). If you follow the "create a simple plugin" walkthrough in the SDK, it is listed as step 3 here: http://msdn.microsoft.com/en-au/library/bb955365.aspx.
The steps it describes are basically as follows:
Right-click your project in Solution Explorer and click Properties.
Create a new strong key file by clicking the Signing tab, select the Sign the assembly check box and select in the drop down list.
Type a name for your key and decide if you need to password your assembly enter the password here or if not, clear the Protect my key file with a password check box.
Save your changes by clicking the Save All button.
The screenshot below shows the Signing Tab & the Create Strong Name Pop up:
Alternatively you can use the sn.exe command line tool. Once you have signed your assembly, you will see a *.snk file listed in your solution explorer.
Tip #2 Register any Interops in the GAC
In my most recent project, I was working with some COM API's to integrate into the clients Line of Business Accounting System. Visual Studio is smart enough to build a COM Interop around any (registered) dll you wish to import, which is very handy - until you try to deploy your plugin to the CRM Server & it has no knowledge of the Interop you are referring to in your code.
You need to make sure that your interop dll is registered in the Global Assembly Cache (GAC) of the CRM Server. The first step you need to keep in mind is that to register your dll into the GAC, your assembly must be signed - so if you followed Tip #1 above you'll be fine! Once your assembly is signed, you can add it to the GAC in two ways, if your a fan of command line utilities, you can use the gacutil.exe command: gacutil /i MyComInterop.dll
I however tend to prefer the GUI tools provided, such as the .NET Framework 2.0 Configuration tool. To use this:
Select Microsoft .NET Framework 2.0 Configuration (CRM 4.0 uses .Net 2.0 by default) from the administrative tools menu
Select Manage the Assembly Cache
Click Add an Assembly to the Assembly Cache (The second option)
Locate your dll using the dialog window that appears and Click Open.
Tip #3 Use the Plugin Registration tool (in the SDK)
The registration of plugins in CRM 4.0 is made so much easier than it used to be in CRM 3.0 - mainly due to the Plugin Registration Tool that ships with the SDK & can be found in the SDK\tools\pluginregistration directory. Some good instructions on how to set it up & use it are listed here, so I wont waste time in repeating them.
What it doesn't mention is what you need to do if you update your Dll's. Initially I wasn’t sure if I had to delete & re-register them, or how to get CRM to recognize that I had updated my dll. If you spent any time at all writing callouts for CRM 3.0 or earlier versions, your first instinct is to stop services, copy over dll's and then restart the services. However you do not need to do this anymore (thank goodness)!
Using the Plugin Registration tool, you can simply:
Copy over your dll's in the server\bin\assembly\ directory
Select the Update option for the selected plugin:
Browse to the new dll file by clicking on the elipse on the update assembly window, and selecting your dll from the dialog window
Select Load assembly
Once the assembly has loaded, select Update Selected Plugins
You will receive a confirmation popup once the system is finished that confirms what has actually been changed
All this occurs without having to restart services - so is seamless to end users and a lot less painful than it was with callouts in CRM 3.0! I really love this change for developing plugins in Microsoft Dynamics CRM 4.0.
So thats it...
So there you have it, my three top tips for CRM 4.0 plugin development. These are the 3 things that I find when working with plugins are not highly documented, but can either save you a lot of time if you know about them - or give you a lot of grief if you forget them! I hope they help you.