Here’s a quick and easy way to update a plugin assembly in CRM to give much quicker turn around when developing. Note: this will only work if the plugin is deployed to the database.

Plugin assemblies work just the same as all other entities in CRM, which means you can make API calls to retrieve, create or update them. While there is a bit of effort involved in creating new assembly records in CRM and all the associated plugins, steps, images etc. If you want all that to remain the same and to just simply update the deployed code, all you need to do is the following:

var pluginAssembly = new Entity("pluginassembly")
{
  Id = new Guid(pluginAssemblyId),
  Attributes =
  {
    {"content", Convert.ToBase64String(File.ReadAllBytes(assemblyPath))}
  }
};

Where pluginAssemblyId is the id of the assembly you want to update, assemblyPath is the path to the assembly file on disk that you want to deploy and crmService is an authenticated OrganizationServiceProxy (see: my previous post to see how to initialise one)

If you don’t know the id of the assembly, you can look it up via the name first:

var pluginAssemblies = crmService.RetrieveMultiple(new QueryExpression("pluginassembly")
{
  Criteria = new FilterExpression
  {
    Conditions = {new ConditionExpression("name", ConditionOperator.Equal, name)}
  }
});
var pluginAssemblyId = pluginAssemblies.Entities[0].Id;

Assuming the plugin name is the same as the assembly file name, you could also just pull this from the path:

var name = Path.GetFileNameWithoutExtension(assemblyPath);