Adding Nuget Packages/Dependent Assemblies into Microsoft D365 CRM Plugin

Introduction

Dive into the intricate world of Microsoft Dynamics 365 CRM plugins with my latest article on C# Corner. This informative piece focuses on the critical aspect of adding NuGet Packages and incorporating dependent assemblies into Dynamics packages. Uncover the secrets of resolving the notorious "could not load assemblies or its dependencies" issue with a step-by-step demonstration.

This guide not only troubleshoots the problem but empowers you to understand the process thoroughly, ensuring you don't fall prey to common mistakes that lead to such issues. Elevate your Dynamics 365 CRM plugin development by mastering the art of handling NuGet Packages and dependencies seamlessly.

Avoid Direct Plugin Project Creation in Visual Studio

  • Never create a Plugin project directly from Visual Studio or any other IDE.

Utilize Microsoft PowerApps CLI

  • Always opt for creating your plugin project using Microsoft PowerApps CLI.
  • This ensures a standardized and reliable development environment.
  • It automatically creates a Nuget Package file that will be used to avoid "Could not load assemblies or its decencies" 

Prerequisites

  • Download and install the Plugin Registration tool from this link Plugin Registration Tool follow the steps as given on Microsoft
    Plugin Registration tool
  • Download and install Microsoft PowerApp CLI from this link Microsoft PowerApps CLI. Complete the installation process
    Microsoft PowerApp CLI
  • Download and install Nuget Package Explorer from this link Nuget Package Explorer open the Nuget Package Explorer

Open CMD and run "pac" command. You will get the information if it is successfully installed as following

pac command

Execute the following command to create plugin project 

  • Browse to the directory where you want to create the plugin project
  • Execute the command on CMD to create plugin project "pac plugin init"

A plugin project will be created at your desired location as follows

plugin project

Click on the CS Proj file and open it in Visual Studio

plugin project

By default, 2 files are automatically created when you create a plugin project as follows

plugin project

plugin project

I have added PgpCore Nuget package to my plugin project for Encryption and Decryption. You can have your own required nuget package as per your need.

PgpCore

Build your project

Build your project

After a successful build, you will get the output result as follows

 Build your project

Browse the directory of your project

Browse the directory of your project

Browse the directory of your project

Open the file Plugin_Project.1.0.0.nupkg in Nuget Package Explorer by double clicking it

Now you can see that this nuget package file contains the information related to the added nuget package of PgpCore that we want to include in our plugin project package as follows. In your case, you can have the required nuget package that you want to add 

Nuget Package Explorer

Now open up plugin registration tool

plugin registration tool

Click to create new connection

plugin registration tool

Provide login details and login

plugin registration tool

Click to Register New Package

plugin registration tool

Import new plugin package

Browse to the directory where your nuget package file was created automatically when you build the project and import this file 

Import new plugin package

Select the Command Data Service Default Solution and import it

Import new plugin package

Click on view and Display by package

plugin registration tool

Now your Plugin Project is successfully registered with all dependent assemblies and ready to use.

plugin registration tool

In conclusion, navigating the intricacies of Microsoft Dynamics 365 CRM plugins demands a nuanced approach, especially when dealing with NuGet Packages and dependent assemblies. This article has delved into the critical process of resolving the persistent "could not load assemblies or its dependencies" issue, offering a comprehensive, step-by-step demonstration.

By following the recommended best practices, such as avoiding direct plugin project creation in Visual Studio and harnessing the power of Microsoft PowerApps CLI, developers can establish a standardized and reliable development environment. The CLI's automatic creation of a NuGet Package file not only streamlines the process but also acts as a preemptive measure against potential issues.

To further facilitate your journey, prerequisites such as downloading and installing essential tools like the Plugin Registration tool, Microsoft PowerApps CLI, and NuGet Package Explorer are highlighted. The guide emphasizes the significance of these tools in ensuring a smooth plugin development experience.

By adopting these practices and incorporating the suggested steps into your workflow, you not only troubleshoot existing issues but also fortify your understanding of the entire process. Take charge of your Dynamics 365 CRM plugin development, elevate your skills, and sidestep common pitfalls by mastering the art of handling NuGet Packages and dependencies seamlessly. Happy coding!


Similar Articles