Wednesday, 28 January 2015

Consolidation of Dll references Using ILMerge For CRM 2015 Online

In CRM 2015 online you can only register a self contained plugin with no references to any other DLLS. The following outlines how to to consolidate mutable plugins together so it is fit to be registered online.
The Scenario Example used is a DLL called ContactPlugin creates a letter on the update of a Contact.
It has a reference another DLL called VS.RSACPC.CRM.DataModel which is an early bound CRUD operation plugin which allows any component to manipulate data in CRM.


1. Download and instal ILmerge form the following link ILMerge. The Compent will automattically be installed at the following path:  C:\Program Files (x86)\Microsoft\ILMerge\
2. Create the ContactPlugin , add a reference to the VS.RSACPC.CRM.DataModel and implement the code to create a letter on update. The code below passes the service connection to the CRUD using the base.Intialise method BusinessRuleBase class and then creates a letter in CRM:
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VS.RSACPC.CRM.DataModel;
namespace ContactPlugin
{
public class ContactUpdate : BusinessRuleBase, IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
base.Intialise(serviceProvider);
Letter letter = new Letter();
letter.Subject = "Test Letter"+ DateTime.Now;
Entity entity = base.Context.PostEntityImages["PostImage"];
letter.RegardingObjectId = new EntityReference("contact", entity.Id);
letter.Create();
}
}
}

3. Set up the project so all DLLs copied to the to a one location (S drive)/ On successful build there will be two Dlls.
ContactPlugin.dll
VS.RSACPC.CRM.DataModel.dll

4. In CMD Use the following command to Merge the two dlls together with the desired name. It includes a reference to the .net framework and a keyfile which is required for all CRM plugins  . Also required for the cloud is s:\Microsoft.Xrm.Client.dll and Microsoft.Xrm.Sdk.Deployment.dll if you require them as they are not available in the cloud
"C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe"  /keyfile:s:\Vulcan.snk /target:library  /targetplatform:v4,"C:\Windows\Microsoft.NET\Framework\v4.0.30319" /out:"s:\SelfContainedPlugin.dll" "s:\NewContactPlugin.dll" "s:\VS.RSACPC.CRM.DataModel.dll" "s:\Microsoft.Xrm.Client.dll"  "s:\Microsoft.Xrm.Sdk.Deployment.dll"

Note:Its worth putting this into a bat file so it can run over and over

5. Once you have the DLL you can register it with plugin registration tool


6. Register the Step and the required Images
7. Test the plugin




No comments:

Post a Comment