Plugins are made possible through the use of an Assemblies, Plugins, and Steps.
When developing plugins for a Solution, these three pieces are registered and seen as components in the Solution's Plug-in assemblies and Plug-in steps sections.
After exporting this kind of Solution containing plugins, tables, apps, and more, the Solution can be imported with no problems to other environments and, if a previous version of the Solution is already in the environment, changes such as adding Plugins and Steps to the Assembly carry over with Upgrades. Yet, a problem seems to occur when a Plugin is removed.
If a Plugin is deleted and unregistered from an Assembly along with its Step(s), everything within the Solution seems to be fine. The Assembly can be updated, Plugins are functional, and the Solution can be exported, then imported to other environments but not if a previous version of the Solution containing that Assembly before Plugin removal is in that environment:
Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
Message: Plugin Assemblies import: FAILURE. Error: Plugin: <NAME OF PLUGIN ASSEMBLY>, Version=<0.1.0.0> ... caused an exception.: Existing plug-in types have been removed. Please update major or minor verion of plug-in assembly. ...
Besides the apparent typos in this error message provided by the system, it gives clear direction to update the Plugin Assembly version.
Best practice tends to be to open the Assembly's Plugin Library in Visual Studio, open Properties, and in the Application tab, open Assembly Information:
Here you can see the Assembly version and File version were changed from 0.1.0.0 to 0.2.0.0 to represent a minor version change.
Major (X.0.0.0) or Minor (0.X.0.0) changes require the Assembly to be completely reregistered into the environment and Solution it is developed in. After doing so, the old Plugin Assembly along with all its Plugins and Steps can be deleted and unregistered as the new Assembly contains them all and is up to date.
After doing so, the Solution can now be imported and imported as a Solution Upgrade. Yet, there is another problem we encountered when upgrading:
Even though the old, deleted, and unregistered Assembly details are not within the Solution Upgrade, they remain in the upgraded Solution alongside the new Assembly after it is complete as a duplicate...
Why is it not removed automatically? Is there a way to have it removed automatically when upgrading? Is there a different method to Assembly versioning that is best practice? Any input or insight is appreciated.
Yes. two options:
Either approach will accomplish your goal of removing the plugin functionality, and both will carry through smoothly in a solution.
Before you object--this procedure is because the Assembly contains the code in question, not the plugin. By deleting the Plugin and NOT the assembly, you are breaking a relationship reference, but not actually removing any code. When Dataverse goes to validate your solution it sees changes have been made to the plugins, but that no change has been made to the assembly, which doesn't make any sense. Hence, it stops you. So, either update the Assembly or don't update the Plugin. Steps are expected to get in-UI changes to toggle them on/off so they do not get validated this way, so unregistering the Step and leaving the plugin alone will accomplish the same goal.