Microsoft Dynamics 365 Blog

A look into the world of Microsoft Dynamics.

How to Create a Plugin for Dynamics 365

Posted by Alanna Friedberg on Apr 26, 2022 10:15:00 AM

How-to-Create-a-Plugin-for-Dynamics-365While 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.

  1. 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.
  2. Enter a name for the assembly you’re building in the Name textbox.
  3. Go to Solution Explorer. Right-click on the project, wait for the context menu to appear, then choose the Manage NuGet Packages… option.
  4. Choose Browse, then enter the search term, “Microsoft.CrmSdk.CoreAssemblies.” Once it pops up, install the most recent version available.
  5. Make sure you click on “I Accept” when the License Acceptance dialog appears.
  6. Once the installation completes, go back to Solution Explorer. Click on the “Class1.cs” file, then select Rename from the menu.
  7. Change the name of “Class1.cs” to something that more closely matches the intent of your plugin.
  8. 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.

  1. Go back to Solution Explorer, then right-click on your plugin project. Select Properties from the context menu.
  2. Select the Signing tab from your project properties, then click the Sign the assembly checkbox.
  3. Go to the Choose a strong name key file dropdown and select New.
  4. Enter text for the key file name, look for the Protect my key file with a password checkbox, and make sure it’s unchecked.
  5. Select OK.
  6. Go to the project properties Build tab and verify that the project’s Configuration is set to Debug.
  7. Hit the F6 key once again to rebuild your plugin.
  8. 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

  1. Download the Plugin registration tool using NuGet or PowerShell, then open it by clicking PluginRegistration.exe.
  2. Connect to your instance by selecting Create new Connection. Make sure you have office 365 selected.
  3. 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.
  4. 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.

  1. Go to the Register drop-down and select the New Assembly option.
  2. 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.
  3. If you’re using Microsoft 365, make sure that you have isolation mode set to sandbox and Database selected for storing the assembly.
  4. Next, click on Register Selected Plug-ins. You should see a confirmation dialog appear.
  5. 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.

Top 5 Hidden Features of Dynamics 365 Business Central

Topics: Dynamics 365