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:
Has anyone had success with this?
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?
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).
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?
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.
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
I was able to add Shared Project and reference it with no issues:
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/
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.
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.
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:
If a add a normal class library project to the solution then can add a reference to shared projects:
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!
Update on this
Removing the <ProjectTypeGuids> element from the csproj file allows a SharedProject to be added. It may break something else
See above from @cchannon
I think the issue about the manifest was caused by an incorrect key file. Was using a pfx, need to use an snk
Join us for the next call on August 17, 2022 at 8am PDT.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.