While Dynamics 365 provides organizations with various ready-to-use business features, your company may have a business scenario that requires something more customized. For that reason, Microsoft made it possible for developers to create Dynamics 365 plugins to handle those situations. We’re going to walk you through the basics of how to how to create a plugin for Dynamics 365.
What is a Plugin?
Plugins are code libraries built by developers when they need to implement customized logic. For example, they can create a plugin specifically for handling accounting processes that aren’t part of the core functionality within Dynamics 365 Finance. After mastering the basics, developers can eventually develop plugins for any Dynamics 365 module.
By using plugins, organizations can optimize Dynamics 365 to fit their core business needs. Those little extras go a long way toward making the application more accessible to workers. The more comfortable they feel within the platform, the more likely they will be to take full advantage of the platform’s available features.
When Should I Use a Plugin?
First, you should understand the difference between a plugin and a workflow. Workflows can trigger limited events, while plugins can handle a lot more. In addition, plugins actively extend the current behavior of Microsoft Dynamics 365 components. Some examples of when you might want to use a plugin include:
- Needing business logic that updates specific fields in a record when creating or updating information using a Dynamics 365 application.
- Wanting to call external web services or other events that call for saving or deleting a record.
- Needing to perform dynamic calculations on field values when a user opens a record.
- Wanting to automate certain processes like sending emails to customers whenever someone triggers a specific event within your CRM.
Creating a Dynamics 365 Plugin with Dynamics 365
Before you get started, you will need access to an integrated development environment (IDE) that lets you write your new plugin using a .Net language like C# or Visual Basic. A class library in the .Net environment gets compiled into a dynamic link library (DLL) file that you must register with your company’s Dynamics 365 instance.
You can download a Visual Studio instance and the .Net framework from the official Microsoft website. Dynamics 365 supports code built using a version of the .Net framework that is 4.5.2 or later. Developers can also find resources for building and extending Dynamics 365 applications here.
Once everything is ready, you can start creating a Dynamics 365 plugin. Note, we’ll be referencing the C# language for this example, but feel free to swap in comparable libraries if you decide to go with a different language.
- Start your instance of Visual Studio, then create a new Class Library project using the .Net framework. Look for the latest version available. Again, make sure it’s at least 4.5.2 or higher.
- Enter a name for the assembly you’re building in the Name textbox.
- Go to Solution Explorer. Right-click on the project, wait for the context menu to appear, then choose the Manage NuGet Packages… option.
- Choose Browse, then enter the search term, “Microsoft.CrmSdk.CoreAssemblies.” Once it pops up, install the most recent version available.
- Make sure you click on “I Accept” when the License Acceptance dialog appears.
- Once the installation completes, go back to Solution Explorer. Click on the “Class1.cs” file, then select Rename from the menu.
- Change the name of “Class1.cs” to something that more closely matches the intent of your plugin.
- You should receive a pop-up that asks you if you wish to rename the class in your project to match your new file name. Select “Yes” to allow the update.
Now that you’ve created your project, you can edit your .cs file to implement the required business logic for your new library. Once you’re done, you’ll need to compile the assembly by hitting the F6 key. Once it compiles without errors, you must sign the plugin.
- Go back to Solution Explorer, then right-click on your plugin project. Select Properties from the context menu.
- Select the Signing tab from your project properties, then click the Sign the assembly checkbox.
- Go to the Choose a strong name key file dropdown and select New.
- Enter text for the key file name, look for the Protect my key file with a password checkbox, and make sure it’s unchecked.
- Select OK.
- Go to the project properties Build tab and verify that the project’s Configuration is set to Debug.
- Hit the F6 key once again to rebuild your plugin.
- Go to Windows Explorer and look for the following path for your newly built project: \bin\Debug\BasicPlugin.dll.
Make sure you change your build version to release when you’re ready to include the plugin with your solution. Next, you’ll learn how to register a plugin in Dynamics 365.
Registering a Plugin in Dynamics 365
- Download the Plugin registration tool using NuGet or PowerShell, then open it by clicking PluginRegistration.exe.
- Connect to your instance by selecting Create new Connection. Make sure you have office 365 selected.
- Enter your Microsoft Account credentials, then click Login. Note that if your account provides access to multiple environments, you’ll need to pick the correct one.
- Once you connect, you should see any existing plugins and workflow activities registered previously.
Now that you’ve accessed the right environment, you can register your new assembly.
- Go to the Register drop-down and select the New Assembly option.
- Click the (…) ellipses button that appears in the Register New Assembly dialog, then look for the assembly you built in the section that went over how to create a plugin for Dynamics 365.
- If you’re using Microsoft 365, make sure that you have isolation mode set to sandbox and Database selected for storing the assembly.
- Next, click on Register Selected Plug-ins. You should see a confirmation dialog appear.
- Click the OK button to close that dialog and the Register New Assembly dialog. The new assembly should now appear.
Once you’ve gotten the hang of how to register a plugin in Dynamics 365, you should look into how to debug a plugin in Dynamics 365 to ensure functionality.
Make the Most of Your Dynamics 365 Instance
Integrated eBusiness Solutions (IES) gives companies what they need to optimize business tools to maximize efficiency within their organization. Learn more about how we can help you take advantage of all Dynamics 365 features by setting up a consultation.