cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mikef1
Frequent Visitor

Difficulty creating a plugin with merged assemblies or shared code

I'm developing a Dataverse plugin. I've setup a solution in Visual Studio 2019 using the PowerPlatform Soltuion and Project templates (here). All works well - I can build and deploy a plugin, add steps etc.


However I now want to add further code in a BusinessLogic project (rather than having all the code in the plugins project) within my VS2019 solution. As the plugin code needs to reside in 1x DLL for uploading to Dataverse, need some way of combining the DLL's from each of these 2x projects.

 

Searching online indicates that there are 3 ways of doing this: ILMerge, ILRepack or shared projects. I've tried each of these without succes:

  • Shared project: Can't add a reference to a SharedProject to a project based on the "Power Platform Plug-in Library" template
  • ILMerge: Added the MSBuild.ILMerge.Task nuget package to the Plugins project. However this stops the plugins project from building with an error about not being able to find the Plugin.dll in the bin\debug directory.
  • ILRepack: Can build and merge the plugin and BusinessLogic dll's but trying to upload this via the Plugin Registration Tool gives a bad image format error.

Has anyone had success with this?

9 REPLIES 9
a33ik
MVP

Hello,

Any of ways should work fine.

Can you please provide a broader description on Adding fo Shared Projects - maybe some screenshots?

Can you please show the script that you use with ILRepack - to be more specific - what version of .Net Framework do you use?

mikef1
Frequent Visitor

Thanks for your quick reply. Some more details:

 

My Visual Studio solution is based on the "Power Platform Solution Template". It contains a CRMPackage project from the "Power Platform Package" template and a Plugins project from the "Power Platform Plug-in Library" template. There's also a class library project called Entities (not based on any templates). The Plugins project references the Entities project. From within VS2019, the solution can build and deploy to Dataverse. All projects based on .Net 4.6.2.

 

However if the code of the Plugins project references the Entities project then D365 throws an error as expected when the plugin fires (because Entities.dll wasn't deployed).

 

Shared Project

From the Plugins project, doing AddReference from the menu shows the "Reference Manager" popup as expected. But this doesn't contain "Shared Projects" on the left menu. Interestingly, doing the same on the Entities project does show SharedProjects - so I assume it's something to do with the template that was used to create the Plugins project?

 

ILMerge

Prior to adding the ILMerge nuget packages, the solution would build successfully. The bin\debug directory of the Plugins project contained plugin.dll and entities.dll as expected (because Plugins references Entities). However after adding "MSBuild.ILMerge.Task " package to the Plugins project, the solution wouldn't build, complaining of not being able to find Plugin.dll in the bin\debug directory.

 

ILRepack

I removed ILMerge and tried ILRepack package. This successfully created a merged Plugin.dll in bin\debug\merged, and judging by it's size, it looked to be a merge of Plugin.dll and Entities.dll. However when trying to upload this to Dataverse using the plugin registration tool, the error said that the dll didn't contain a manifest file

 

Any ideas?

a33ik
MVP

I was able to add Shared Project and reference it with no issues:

SharedProject.png

 

Regarding the usage of ILMerge, I used this one - https://nishantrana.me/2017/05/17/using-ilmerge-for-plugin-in-crm/ and it worked with no issues.

I don't have an experience using ILRepack personally, check this post - https://fixrm.wordpress.com/2019/06/10/one-more-way-to-merge-assemblies-for-d365-ce/

 

 

 

mikef1
Frequent Visitor

Thanks for looking into this.

In your screenshot, is the solution and/or the project created from the Power Platform templates?

I'm wondering if it's the template(s) that are causing my issues.

a33ik
MVP

The solution was not there initially but it was created once I opened the project using VS.

mikef1
Frequent Visitor

Was the project created from the PowerPlatform template?

I will try it (create project from a template but use a vanilla solution).

Will report back tomorrow.

mikef1
Frequent Visitor

I created a new project based on the PowerPlatform plugins template. Added a SharedProject to the solution.

Can't add reference from the plugins project to the shared project - see screenshot:

mikef1_0-1642673666933.png

 

Using VS2019:

mikef1_1-1642673757547.png

 

If a add a normal class library project to the solution then can add a reference to shared projects:

mikef1_2-1642673922571.png

 

cchannon
Super User
Super User

Yes, ILMerge is the way to go for this, and I've done it myself, but it is unsupported by Microsoft. This has been the case for over a decade now and a source of constant frustration for many developers. But there is new hope: coming soon (next month, supposedly) we will be getting a new feature called Dependent Assemblies that will eliminate these ILMerge headaches once and for all. Hopefully you can wait that long!

 

https://docs.microsoft.com/en-us/power-platform-release-plan/2021wave2/data-platform/dependent-assem...

mikef1
Frequent Visitor

Update on this

 

SharedProjects

Removing the <ProjectTypeGuids> element from the csproj file allows a SharedProject to be added. It may break something else

 

ILMerge

See above from @cchannon 

 

ILRepack

I think the issue about the manifest was caused by an incorrect key file. Was using a pfx, need to use an snk

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (3,869)