{Back to Basic} Create a Plugin
Visual Studio is best tool for Creating a plugin for MS CRM/MS D365.
Open Visual studio
Select New Project in start Page
If you don’t see start page, Go to File > New > Project.
In New project wizard, Under Visual C# Select Class Library , Class Library is the project which create’s Dll, and Project Name and Solution Name and click OK
Plugin is nothing but a collection of class(s) in Class Library dll assembly which has C# code.
You register a class library dll assembly in plugin registration tool and This dll can have one or more class which act as a plugin.
Once Project is ready with solution, you will get a default class,
You can rename or delete and create new.
I Prefer deleting and creating new Class.
Name the class “MyTestPlugin”.
Now Open Nuget Package Manager Console.
Tools > Nuget Package Manager > Package Manager Console
No need to download SDK anymore, now the only way to add SDK assemblies for CRM V 9.0 is through Nuget Manager.
Even tools such as Plugin registration is available on Nuget.
{we will see this in upcoming blog}
Now, Run Following Nuget Package command in Package Manager Console.
Install-Package Microsoft.CrmSdk.CoreAssemblies -Version 9.0.2.5
This will install Required Dll
Once Installation is done
Go to MyTestPlugin Class,
> using Microsoft.Xrm.Sdk; Namespace.
> And Inherit IPlugin interface
IPlugin interface is a gate.
A gate which is recognized in CRM Event Execution Pipeline.
While registering plugin, Plugin Registration tool will check for the class which inherits this interface and add it to event execution pipeline based on steps selected.
Implement IPlugin Interface, this will add Execute Method with IServiceProvider as a parameter.
Final Code will look like below.
using Microsoft.Xrm.Sdk;
using System;
using System.ServiceModel;
namespace BlogPlugin
{
public class MyTestPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Validate that there is a service provider, otherwise no point.
if (serviceProvider == null)
throw new ArgumentNullException("No Service Provider Found");
try
{
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
}
}
Plugin is ready but one last step is Required and is very important.
signing in the Assembly.
Without signing, Plugin registration tool will not allow you to register plugin assembly.
To Register,
Right Click on Plugin Assembly Class library Project, Select Properties and go to Signing Tab.
Signing Plugin Assembly
Check the check box Sign in Assembly, Select new in Drop down
You can create a key with password or even without password.
I prefer creating without password.
Uncheck the check box protect my key file with a password.
Add Key Name “SecureKey” and click ok
This will create a file to your project called SecureKey.snk
Now Build your Project.
And your simple Plugin is Created.

Like
Report
*This post is locked for comments