$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
Dynamics 365intermediateNew

Dynamics 365 Plugin

Share

Build C# plugins with pre/post operation steps and execution pipeline

Works with OpenClaude

You are a Dynamics 365 developer building custom C# plugins to intercept and manipulate data during CRM operations.

What to check first

  • Verify Dynamics 365 SDK is installed: check your .csproj file contains Microsoft.CrmSdk.CoreAssemblies NuGet package
  • Confirm plugin registration tool is available: C:\Program Files\Microsoft Dynamics CRM\Tools\PluginRegistrationTool.exe (or latest version path)
  • Check your plugin assembly targets .NET Framework 4.6.2 or higher (or .NET 6.0 for newer SDK versions)

Steps

  1. Create a new C# class library project targeting .NET Framework 4.6.2
  2. Install Microsoft.CrmSdk.CoreAssemblies NuGet package (Install-Package Microsoft.CrmSdk.CoreAssemblies)
  3. Inherit your class from IPlugin interface and implement the Execute(IServiceProvider serviceProvider) method
  4. Extract the execution context using serviceProvider.GetService(typeof(IPluginExecutionContext)) cast to IPluginExecutionContext
  5. Determine execution stage (Pre = 10, Post = 40) via executionContext.Stage property
  6. Check executionContext.Depth to prevent infinite loops (typically avoid running if Depth > 1)
  7. Retrieve the entity from executionContext.InputParameters["Target"] as Entity type
  8. Access organization service via serviceProvider.GetService(typeof(IOrganizationServiceFactory)) to perform CRM operations
  9. Register the plugin using Plugin Registration Tool, specifying the message (Create, Update, Delete, etc.), entity, and stage (Pre/Post)

Code

using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

public class AccountPreCreatePlugin : IPlugin
{
    public void Execute(IServiceProvider serviceProvider)
    {
        IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        
        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
        {
            Entity entity = (Entity)context.InputParameters["Target"];
            
            // Only execute on Create message, Pre-operation stage
            if (context.MessageName == "Create" && context.Stage == 10)
            {
                // Prevent infinite recursion
                if (context.Depth > 1)
                    return;
                
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                
                // Business logic: Set default account rating
                if (!entity.Contains("account

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryDynamics 365
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
dynamics365plugincsharp

Install command:

curl -o ~/.claude/skills/d365-plugin.md https://clskills.in/skills/dynamics365/d365-plugin.md

Related Dynamics 365 Skills

Other Claude Code skills in the same category — free to download.

Want a Dynamics 365 skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.