Home › Dynamics 365 Customer Engagement (CRM) › Coding Multiple Plugins in One Assembly in Dynamics 365
Dynamics 365 Customer Engagement (CRM) · Apr 17, 2018 · 2 MIN READ

Coding Multiple Plugins in One Assembly in Dynamics 365

In this post we will look at how to code 2 plugins in one assembly. This might be useful if you want to keep related pieces of code under the same code base.

Let’s create a new VS project:

Rename the class to Plugins:

Add Microsoft.CrmSdk.CoreAssemblies through NuGet.

Add the code. We will add 2 functions, Plugin1 and Plugin2:

The code will write a Plugin Trace Log entry.

[sourcecode language=”CSharp”] using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;

namespace Carl.MultiplePlugins
{
public class Plugin1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracingService.Trace("Plugin 1.");
}
}

public class Plugin2 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracingService.Trace("Plugin 2.");
}
}

}
[/sourcecode]

 

Sign and build the project.

Now in the Plugin Registration Tool, select the assembly to register it. We see it is picking up there are 2 plugins:

And 2 have been registered:

We see the plugins:

Right-click the first plugin to add a step:

Let’s run this on create of an Account:

And the second one, create of a Contact:

Ensure plugin tracing is turned on in System Settings.

Now create an Account.

Go to Plugin Trace Logs in Advanced Find:

Plugin 1 is written to the log:

Now create a Contact. Plugin 2 has run.

 

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

Leave a Reply

Your email address will not be published. Required fields are marked *

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.