Master Yoda
Master Yoda

Reputation: 4422

CRM using ILMerge to merge framework library with plugin projects

I have two assemblies:

  1. Main plugin assembly - Plugin used for my project
  2. Framework assembly - I want to merge this assembly with the main plugin so I can reuse some common methods used a lot in different projects.

I installed ILMerge on the main plugin assembly and referenced the built out framework dlls while simultaneously setting project build order on the solution.

Now, this looks okay before I deploy. The main problem comes when I try to debug using my unit tests project.

In my unit tests project, I have a reference to the main plugin assembly which allows me to use fakexrmeasy to run my unit tests. However, now that the assemblies have been merged I expect that I should be able to use the framework methods within my unit tests project. I cant seem to access those methods when referencing the main plugin assemblies in the test classes.

All of the projects mentioned above exist within the same solution.

Im fairly new to ILMerge so might be doing something wrong thats glaringly obvious. I just compile using the built in visual studio compiler.

Can anyone suggest what could be going wrong?

Upvotes: 2

Views: 1659

Answers (2)

Henk van Boeijen
Henk van Boeijen

Reputation: 7948

First, my advice is to use ILRepack, since ILMerge is no longer being actively maintained. ILRepack is based on ILMerge and is open source. Add NuGet package ILRepack.Lib.MSBuild.Task to your project.

Then add this file to your project and name it ILRepack.targets:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="ILRepacker" AfterTargets="Build">
    <ItemGroup>
      <InputAssemblies Include="$(OutputPath)$(TargetName)$(TargetExt)" />
      <InputAssemblies Include="$(OutputPath)YourFramework.dll" />
    </ItemGroup>
    <ILRepack
        Parallel="true"
        Internalize="false"
        InternalizeExclude="@(DoNotInternalizeAssemblies)"
        InputAssemblies="@(InputAssemblies)"
        LibraryPath="$(OutputPath)"
        Wildcards="false"
        TargetKind="SameAsPrimaryAssembly"
        DebugInfo="false"
        KeyFile="YourCompany.snk"
        OutputFile="$(OutputPath)Merged\$(AssemblyName).dll"
        LogFile="$(OutputPath)Merged\ILRepack.log"
    />
  </Target>
</Project>

Note according to this configuration your merged dll is created in a separate folder named "Merged". This is the library you register on Dynamics 365. Your unit tests should simply use the plugin project's regular build output.

Upvotes: 3

Aron
Aron

Reputation: 3945

As long as you have all the code for the framework assembly, one option would be to use a Visual Studio Shared Project.

Putting the framework code into a shared project would allow you to compile your plugin and the framework code into a single assembly without any additional tools.

In this answer I covered how I typically use Shared Projects to make plugin logic accessible from both the plugin assembly and a Console App for testing/debugging.

Another option would be to add the framework source files as links to the plugin project.

Upvotes: 1

Related Questions