Create XrmToolBox Plugin – Part 1: Set-up Visual Studio and create a basic plugin

Recently I created my first XrmToolBox plugin User Security Manager and successfully released this to the plugin store. I followed XrmToolBox for developers and the other resources available on the internet but creating a plugin was not so smooth for me, so I thought of writing my experiences and detailed step by step guide.

I will detail the entire process in 4 different blogs this is my first blog in this series.

  1. Create XrmToolBox Plugin – Part 2: Debug XrmToolBox Plugin
  2. Create XrmToolBox Plugin – Part 3: Package your plugin
  3. Create XrmToolBox Plugin – Part 4: Setup build definition release fo CI and CD


  1. Visual Studio 2017

Step 1: Download and install XrmToolBox Plugin Project Template: download VS 2017 project template and install on your dev machine.

Step 2: Open VS 2017 and go to File -> New -> Project…, it will open a new project window.

  1. Click on “Installed” (1) template and search for “Xrm” (2). You will see the above-installed plugin (3).
  2. Give a meaning full name to your plugin (4) and click OK(5).

  1. Click on “Trust” if you get following warning message.

Step 3:
Update Plugin Metadata open file “MyPlugin.cs” and update the following metadata details

  1. Name: Name of your plugin. It will appear in XrmToolBox plugin list and plugin store.
  2. Description: Short description of your plugin. It will appear in XrmToolBox plugin list and plugin store.
  3. SmallImageBase64: 32*32 logo of your plugin, to generate a base64 string of your plugin logo you can use this URL.
  4. BigImageBase64: 80*80 logo of your plugin, to generate a base64 string of your plugin logo you can use this URL.
  5. BackgroundColor: background color of your plugin
  6. PrimaryFontColor: Primary font color of your plugin
  7. SecondaryFontColor: Secondary font color of your plugin

Step 4: Build your plugin logic At this point you are all set to start building your logic into the plugin. You can create UI and add code logic but still, you cannot run/debug it. In my next blog I will talk about debugging, but before we go there let’s elaborate on the various components of this project, do’s and don’ts. (below is how default project structure will look like)

  1. MyPlugin.cs: This file contains all necessary metadata that defines your plugin, please make sure you have provided all the values in this file as described above.
  2. MyPluginControl.cs: all your plugin logic goes here or gets invoked from here.
    1. If your plugin logic is simple and does not requires much coding you can put everything in this class file (this is just my opinion).
    2. If your plugin logic is complex, and you are using some design pattern then this is the class where you will initialize your child components, controls.
    3. MyPluginControl_Load: You can put your initializing logic here. Like configuring the plugin as per the user settings, or resuming the plugin last used state etc.

    4. MyPluginControl_OnCloseTool: Your plugin close logic (if any) goes here.

    5. UpdateConnection: If you want to configure the behavior of your plugin on change of CRM connection, then you need to inject your logic here. For example, if you want to reload data from new CRM organization on XrmToolBox connection change, you can invoke that logic from this function.

    6. If your plugin needs multiple organization connections (one such example is if you are creating a plugin to move data from once CRM org to another CRM org), then you need to inherit “MultipleConnectionsPluginControlBase” class and implement “ConnectionDetailsUpdated” method. By default “MyPluginControl” class inherits “PluginControlBase” base call which provides access to only one Organization connection at a time.

      If you inherit “MultipleConnectionPluginControlBase” then you need to implement “ConnectionDetailsUpdate”

  3. Do’s and Don’ts:
    1. To ensure that Organization service is available when you execute your logic use “Service.Execute(<<your function name>>());” instead of invoking you function directly.

    1. Your plugin logic should be asynchronous, it should not block the tool itself. Use function “WorkAsync” and class “WorkAsyncInfo” to invoke your logic asynchronously, for details see here.

    1. Add proper logging to your plugin. “PluginControlBase” class provides 3 helper methods that you can use.

    1. Do not use early bound classes with your plugin.
    2. Your plugin should open with or with or without a connection available in XrmToolBox.

Hope It helps. In the next blog, I will explain how to debug your plugin in visual studio.

3 thoughts on “Create XrmToolBox Plugin – Part 1: Set-up Visual Studio and create a basic plugin

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s