A Dynamics 365 plugin is a custom piece of code (written in .NET languages like C#) that you can register and execute within the Dynamics 365 platform in response to specific events or messages. Think of them as event handlers that allow you to extend and modify the standard behavior of Dynamics 365.


Here’s a breakdown of what that means:

  • Custom Business Logic: Plugins enable you to implement business rules, validations, data manipulations, integrations, and other custom functionalities that are not available out-of-the-box in Dynamics 365.  
  • Event-Driven: Plugins are triggered by specific events that occur within Dynamics 365, such as creating a new record, updating an existing one, deleting a record, assigning a record, and many other system operations.  
  • Server-Side Execution: Plugins run on the Dynamics 365 server, meaning the logic is executed in the backend.  
  • Integration Point: They act as a powerful way to integrate Dynamics 365 with other systems, web services, or custom applications.  
  • Automation: Plugins are commonly used to automate tasks and enforce business processes seamlessly within the CRM.

For example, you could write a plugin to:  

  • Automatically send a welcome email whenever a new account is created.
  • Prevent saving a lead if a required field is missing in related account.
  • Update related records when a field in the current record is changed.
  • Call an external service to validate an address.

Plugins are a fundamental tool for customizing and extending Dynamics 365 to meet specific business requirements. They offer a high degree of flexibility and control over the platform’s behavior.


Prerequisites

To get started, make sure:

  • You have Visual Studio 2019 or Visual Studio 2022 installed.
  • During installation (or open Visual Studio Installer and modify), include:
    • .NET desktop development workload
    • .NET Framework 4.7.2 development tools (widely used and stable, and recommended for new development.)
    • Or .NET Framework 4.6.2 (minimum required for most current plugin development.) (Or 4.8 also supported, still I suggest 4.7.2)
    • Azure development (optional, if you’re working with Azure Functions for external integration)
  • Plugin Registration Tool (comes with the SDK or available via XrmToolBox) (you will find the Installation steps later in the blog)
  • Knowledge Requirements:
    • Basic C# knowledge
    • Understanding of Dynamics 365 data model
    • Familiarity with SDK concepts

Step-by-Step Plugin Development

Creating the Plugin Project:

  1. Open Visual Studio (2019 or 2022).
  2. Go to File > New > Project. (Or Click “Create a new Project” as shown below)
  3. Select Class Library (.NET Framework) (see below image (2nd)).
  4. Click Next, then:
    • Project Name: e.g., AccountPlugin
    • Location: Choose a directory
    • Framework: Select .NET Framework 4.7.2 (or 4.6.2 / 4.8 if needed) (See below image 3rd)
  5. Click Create.

Adding Required NuGet Packages:

Go to Tools -> NuGet Package Manager -> Manage NuGet Package for Solution

Browse crm and you will find “Microsoft.CrmSdk.CoreAssemblies”, which contains core CRM SDK classes like IPlugin, IServiceProvider, IOrganizationService, etc., install it.

Additional packages are available for installation based on your specific requirements. However, they are not necessary for the current project and are listed below for your information.

  • Microsoft.CrmSdk.Workflow – Only needed if you’re developing workflow activities
  • Microsoft.CrmSdk.XrmTooling.CoreAssembly – Useful for console apps/tools connecting to CRM
  • Newtonsoft.Json – For handling JSON (e.g., when calling external APIs)
  • Polly – Retry logic when calling APIs
  • Microsoft.Extensions.Logging – Structured logging support (if you’re doing advanced plugin diagnostics)

Sample Plugin Class Skeleton

Best Practices:

Error Handling

  • Always wrap your logic in try-catch blocks
  • Use InvalidPluginExecutionException to raise errors back to CRM
  • Log everything to ITracingService

Logging

Use ITracingService.Trace() generously — especially during development or debugging.

Logs are viewable in Advance Settings -> Customizations -> Plug-In Trace Log in Dynamics 365 if enabled.

Avoiding Infinite Loops

Plugins can trigger themselves if they update the same entity — this is called a recursive loop.

Prevent this by:

  1. Using depth check:

2. Using pre-image comparison:

3. Only update fields if needed, not blindly.

Example Plugin Scenarios

Example 1: Set a field when account is created

Example 2: Prevent duplicate contact email on create

Pro Tips

  • Always test plugins in a dev environment before production.
  • Use Plugin Profiler in the Plugin Registration Tool to debug in-depth.
  • Keep your plugin class focused — if it does too much, split into smaller classes.

Signing the Assembly

Why Signing Is Important

  • Dynamics 365 Online requires all plugins to be strong-named.
  • A strong-named assembly has a unique identity (name + version + culture + public key).
  • It prevents conflicts, allows for assembly versioning, and ensures security & trust.
  • Without signing, registration of the plugin will fail in Dynamics 365 online environments.

How to ?

  • Right-click your plugin project > Properties.
  • Go to the Signing tab.
  • Check “Sign the assembly”.
  • From the dropdown, choose:
  • <New…> to create a new strong name key.
  • Name it something like PluginKey.snk.
  • You can leave the password field blank for simplicity (or protect it if needed).
  • Save and rebuild.

Building the Solution

Debug vs Release Configurations

ConfigurationPurposeWhen to Use
DebugIncludes debug symbols, no optimizations, larger file sizeDevelopment and local testing
ReleaseOptimized code, smaller assembly, no debug symbolsFinal build for production and registration

Handling Dependencies

When registering plugins, all your referenced assemblies (besides the standard SDK libraries) need to be handled carefully.

Best Practices:
  1. Avoid unnecessary third-party dependencies.
    • Every dependency increases size and potential issues in the sandbox.
  2. Use ILMerge (or ILRepack) to merge dependencies into a single DLL (if needed).
    • This is especially useful if you’re using third-party libraries (e.g., Newtonsoft.Json).
    • Example command:

Output Location

After a successful build:

  • Go to your project’s bin\Release folder.
  • You’ll find:
    • YourPlugin.dll
    • Possibly .pdb (symbols file — not needed unless debugging with Plugin Profiler)
    • Any other dependency DLLs if applicable

Deployment to Dynamics 365

Using Plugin Registration Tool

The Plugin Registration Tool (PRT) is a powerful utility in the Dynamics 365 SDK that allows you to register, update, and manage custom plugins and custom workflow activities. Below is a detailed walkthrough covering:

  • Registering Assemblies
  • Registering Plugin Steps
  • Using Secure Configurations
  • Updating Existing Plugins

Make sure you’ve downloaded the latest Plugin Registration Tool.

Installation:

First Install Power Platform CLI: https://aka.ms/PowerAppsCLI

Then: run this command in terminal: pac tool prt

Now launch the Plugin Registration Tool:

First Connect: using email and password

Now let’s register the plugin. Register -> Register New Assembly

Now Let’s add Step for the plugin. (A step is is trigger point, like on Create, on Delete, etc.)

Once you’ve added your plugin step, your plugin is officially registered and ready to go!

At this point, Dynamics 365 will automatically trigger your plugin when the specified message and entity event occurs (e.g., when a Create action happens on a Contact record).

Now it’s time to test and debug your plugin:

  • Try performing the action in the system (like creating or updating a record) that should trigger your plugin.
  • Check if the expected behavior occurs.
  • If something doesn’t work as expected, double-check:
    • The assembly and step registration details
    • The plugin logic itself
    • Any error messages in the Plugin Trace Logs (if enabled)

Tip: You can enable plugin trace logging in System Settings > Customization > Plug-in Trace Log, which is super helpful for debugging.

Once you confirm your plugin is working as intended, you’re all set to continue building more logic or deploying to other environments.


Additional Resources

Here are some helpful links to deepen your understanding and stay up to date:

Keep Experimenting!

Don’t be afraid to experiment with plugins in a dev environment. Test different trigger points, try out secure configurations, and explore asynchronous steps. The more you play with it, the more comfortable you’ll become.

Thanks for sticking with me all the way to the end—hope this guide helped make the Plugin Registration Tool a little less intimidating!

If you run into any issues or have questions, feel free to drop a comment below. I’m happy to help out or clarify anything.

One response to “Building Your First Dynamics 365 Plugin: From Setup to Deployment”

  1. Unlocking Dynamics 365 with Delete Plugins and Pre-Images – Dynamics Services Group Avatar

    […] If you are new to PlugIn development, please first read this blog: Building Your First Dynamics 365 Plugin: From Setup to Deployment – Dynamics Services Group […]

    Like

Leave a comment

Copyright © 2026 Dynamics Services Group