[Bonus] Setting Up Visual Studio Code for Dynamics 365 CRM Plugin Development

[Bonus] Setting Up Visual Studio Code for Dynamics 365 CRM Plugin Development

Before going further in our plugin journey, let’s make sure your environment is ready! This bonus guide walks you step by step through setting up Visual Studio Code for Dynamics 365 CRM plugin development—including both command-line (shell) and mouse-click (GUI) instructions. You’ll also learn how to write your first C# plugin, and discover some time-saving VS Code shortcuts and extensions.


1. Prerequisites

  • .NET SDK (4.6.2 or later for most Dynamics 365 plugins)
  • Visual Studio Code (latest version)
  • Plugin Registration Tool (PRT) for deployment
  • Access to a Dynamics 365 environment


2. Installing Visual Studio Code & Extensions

A. Download and Install VS Code

Mouse Clicks:

Shell:

  • (Windows) Use the installer as above.
  • (macOS)
  • (Linux - Ubuntu)


B. Install Required Extensions

Mouse Clicks:

  • Open VS Code.
  • Click the Extensions icon (or press Ctrl+Shift+X).
  • Search for and install:C# (by Microsoft)NuGet Package Manager.NET Install ToolGitLensPower Platform Tools (optional)

Shell:

code --install-extension ms-dotnettools.csharp
code --install-extension jmrog.vscode-nuget-package-manager
code --install-extension ms-dotnettools.vscode-dotnet-runtime
code --install-extension eamodio.gitlens
code --install-extension microsoft-IsvExpTools.powerplatform-vscode        

3. Creating a Plugin Project

A. Create a New .NET Class Library

Mouse Clicks:

  • Open VS Code.
  • Click View > Terminal (`Ctrl+``) to open the integrated terminal.
  • In the terminal, run:


B. Add Dynamics 365 SDK Assemblies

Mouse Clicks:

  • In VS Code, open the terminal (`Ctrl+``).
  • Run:

Alternative (Mouse):

  • Open the Command Palette (Ctrl+Shift+P).
  • Type "NuGet Package Manager: Add Package".
  • Search for Microsoft.CrmSdk.CoreAssemblies and add it.


4. Writing Your First C# Plugin

Mouse Clicks:

  • In the Explorer panel, open Class1.cs (rename as needed).
  • Replace the code with:

using System;
using Microsoft.Xrm.Sdk;

namespace MyFirstPlugin
{
    public class SamplePlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)
                serviceProvider.GetService(typeof(IPluginExecutionContext));

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)
                serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            // Trace log
            ITracingService tracingService = (ITracingService)
                serviceProvider.GetService(typeof(ITracingService));
            tracingService.Trace("SamplePlugin execution started.");

            // Plugin logic
            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity entity)
            {
                entity["description"] = "Updated by SamplePlugin at " + DateTime.UtcNow;
            }
        }
    }
}        

5. Building and Packaging the Plugin

Mouse Clicks:

  • Open the terminal in VS Code (`Ctrl+``).
  • Run:
  • The DLL will be in bin/Debug/net462 (or another relevant folder).


6. Deploying the Plugin (Plugin Registration Tool)

Mouse Clicks:

  • Download the Plugin Registration Tool (docs).
  • Extract and open the tool.
  • Click Create New Connection, enter your environment details, and connect.
  • Click Register > Register New Assembly, select your DLL, and complete the registration steps (refer to Part 2 of this series for details).


7. Cool VS Code Shortcuts for Productivity

  • Open Command Palette: Ctrl+Shift+P
  • Quick file open: Ctrl+P
  • Go to symbol: Ctrl+Shift+O
  • Format document: Shift+Alt+F
  • Rename symbol: F2
  • Peek definition: Alt+F12
  • Multi-cursor editing: Alt+Click
  • Toggle terminal: Ctrl+`
  • Open extensions: Ctrl+Shift+X
  • Open Problems panel: Ctrl+Shift+M


8. Recommended Extensions for Plugin Developers

  • C#
  • NuGet Package Manager
  • GitLens
  • Power Platform Tools (for Dataverse/CRM integration)
  • REST Client (for quick API testing)
  • Bracket Pair Colorizer (visual aid for bracket matching)


9. VS Code Settings for C# Plugin Development

Add to your settings.json for an improved experience:

{
  "editor.formatOnSave": true,
  "csharp.format.enable": true,
  "files.exclude": {
    "**/bin": true,
    "**/obj": true
  }
}        

10. Extra Tips

  • Source Control: Use Git (git init) and GitLens.
  • Snippets: Save repetitive code as snippets.
  • Debugging: Use ITracingService for logs and enable Plugin Trace Logs in Dynamics 365.


11. Further Reading


With both mouse and shell options, you can set up your environment your way! Let me know your favorite VS Code tips or extensions in the comments.

#Dynamics365 #PluginDevelopment #CSharp #VSCode #PowerPlatform #MSDyn365 #CRM #Developers #Productivity #CodingTips #VisualStudioCode

To view or add a comment, sign in

More articles by Nithin Krishna B.

Others also viewed

Explore content categories