Now I want to share how to merge multiple assemblies in Dynamics CRM Environment. We used ILRepack as our merge tool because the result is smaller compare to ILMerge.
For this tutorial, we will embed the command for merging in .csproj, so every time we build our project. The result in the bin folder is being merged already.
- In your current project, right-click and add NuGet package > search ILRepack and installed it. Or you can open Nuget Package Manager and install it using “Install-Package ILRepack -Version 2.0.15“
- After finished download and set up your NuGet, save all of your projects. Then open your .csproj with other editor and put the command for merging
Here is the command:
<Target Name="AfterBuild">
<ItemGroup>
<InputAssemblies Include="$(TargetPath)" />
<!-- Framework -->
<InputAssemblies Include="$(TargetDir)Niam.XRM.Framework.dll" />
<InputAssemblies Include="$(TargetDir)Plugins1.dll" />
</ItemGroup>
<ItemGroup>
<KeyFile Include="$(ProjectDir)key.snk" />
</ItemGroup>
<Exec Command="$(ILRepack) /keyfile:@(KeyFile) /parallel /out:$(TargetPath) /lib:$(TargetDir) @(InputAssemblies -> '%(Identity)', ' ')" />
</Target>
You can put all the needed assemblies in that configuration and don’t forget to put the .snk file also. For this example I put the key.snk.
When you build your project, you will notice in your output will have this result:

For checking, you can open your DLL using ILSpy to check if is it already merged or not:

2 thoughts on “Dynamics Crm Merge Assemblies”