Plugin Project Structure and Coding Foundation
Plugin Project Structure and Coding Foundation
With the development environment and tools ready, the next step is to organize your project files so you can begin writing plugin logic that Dynamics CRM will accept and run.
Project Creation and Naming
In Visual Studio, create a new project using the Class Library (.NET Framework) template. Use a clear naming pattern such as CompanyName.Plugins.EntityName. For example, a plugin for the Account table could be named LS.Plugins.AccountPlugins. Make sure the project targets .NET Framework 4.6.2, as this is required for compatibility with Dynamics CRM.
Signing the Assembly
Before a plugin can be registered in CRM, its assembly must be signed with a strong name key. In Visual Studio, open the project properties and go to the Signing tab. Check Sign the assembly, then create a new key file such as key.snk. For simplicity during development, you can choose to proceed without password protection.
Installing Core SDK Assemblies
Your project needs specific libraries to interact with Dynamics CRM data and services. Use the NuGet Package Manager to install Microsoft.CrmSdk.CoreAssemblies. This package includes essential types such as the IPlugin interface and the Microsoft.Xrm namespaces.
Implementing the Plugin Boilerplate
To streamline development and maintain consistency, create a boilerplate base class for your plugins. Add a new class file named PluginBoilerplate.cs and paste in your standard template code. This abstract class defines a structure that all your plugin classes will follow and centralizes common logic and references.
Creating Your Plugin Class
With the boilerplate in place, rename the default Class1.cs file to something that reflects the plugin’s purpose, such as CapitalizeAccountName. Have your class inherit from the boilerplate base class. Use Visual Studio’s Quick Actions to implement the abstract class, which generates an Execute method. This method gives you access to three key services used in plugins:
- IPluginExecutionContext — information about the operation and the data that triggered the plugin
- IOrganizationService — the primary API used to create, update, and delete CRM records
- ITracingService — a logging facility to assist with debugging
Organizing your project files in this way ensures that each plugin class follows a standard structure, making the code easier to maintain and extend over time.
Comments
Post a Comment