The latest version of the Microsoft Dynamics 2011 SDK comes with some sweet extensions and tools as a part of the Developer Toolkit. This includes some Visual Studio 2010 integrated features for developing and deploying plugins. This makes it easier than ever to develop extensions for Microsoft Dynamics CRM with advanced features such as incorporating Web Resources and using early bound types via an easily generated strongly typed proxy class file.

  1. Download and install the latest MS Dynamics CRM SDK from Microsoft. Link: Microsoft Dynamics CRM 2011 Software Development Kit (SDK)
  2. Launch Visual Studio 2010. Create a new Project. Select the Template library for “Dynamics CRM” and select the Solution Template “New Visual Studio Solution Template for Dynamics CRM 2011.”
  3. Enter your connection details, and select the targeted CRM Organization and Solution. Click OK.
  4. Uncheck the “Host the Silverlight application in a new Web site” unless you plan on doing Silverlight development in this solution (not covered in this tutorial). Click OK.
  5. By default, your solution contains projects for a Deployment Package, Plugins, Silverlight Applications, and Workflows. In this tutorial, we are only interested in the Deployment Package and Plugins projects. So, right click on the SilverlightApplication project and click “Remove” and do the same for the Workflow project.
  6. Once in your new solution, go to View > CRM Explorer.
  7. If you want to work with early bound types, you can generate and incorporate the code file by right clicking on Entites and clicking “Generate Wrapper.” This may take a few minutes, but it’s easier than using CrmSvcUtil.exe!
  8. If you want to work with Web Resources, you can add those as well but right clicking on Web Resources and clicking “Add to packaging project.” It’s best just to add the specific resource you will be using rather than all of them, so you can expand the node and type and find the specific resources needed.
  9. Expand the Entities node and find the targeted entity for your plugin. Right click and click “Create Plug-in.”
  10. The dialog box that pops up should look familiar if you’ve registered plugins before using the Plugin Registration Tool. Select your plugin properties and create OK. For this tutorial, the plug will run after creation of an Account record. Enter or select the following and press OK to generate the base code for the plugin:
    1. Message: Create
    2. Run in Context: System Administrator
    3. Execution Order: 1
    4. Pipeline Stage: Post-Operation
    5. Execution Mode: Synchronous
    6. Deployment: Server Only
  11. In Solution Explorer, open the PostAccountCreate.cs class file. Scroll down and find the comment “TODO: Implement your custom Plug-in business logic.” Insert your main plugin execution code there. In this example:thrownewInvalidPluginExecutionException(“Hello World!”);
  12. Right click on the Plugins project and click “Properties.” Under the Signing tab, check the “Sign the assembly” and choose “<New…>” from the drop-down. Enter a key file name click OK.
  13. In Solution Explorer, right click on the Solution and select Deploy Solution.
  14. Log in to CRM and create a new Account. Fill in the Account Name and click Save. Your plugin will fire, and a modal dialog box will appear due to the unhandled exception in the code saying “Business Process Error Hello World!”

Some additional notes:

  • Don’t forget to unregister or disable your plugin! Otherwise, it might prevent others from completing CRM actions.
  • If you thrown an InvalidPluginExecutionException from a plugin, note that the entire transaction will be rolled back. In this case, the Account record will not be saved.
  • You can use the tracing service to log debugging information to the Log File, accessible from the error message pop-up. To use, simply run the Trace() method in the LocalPluginContext:localContext.Trace(“foo”);
Like this post? Share it!