There may be situations where it is necessary to merge the SpAgent runtime assemblies with the licensed assemblies in an application. This is necessary where:
- Only a single assembly can be deployed e.g. in a Dynamics CRM solution typically only one DLL can be deployed to the CRM platform, whether on-premise or in the cloud
- The licensed assembly is deployed in the GAC e.g. in a sharepoint solution where the licensed assembly may be used by multiple solution components.
Merging SpAgent assemblies using ILRepack
The following is our recommended approach to merging the SpAgent assemblies with the licensed assembly as part of the build process using ILRepak:
Step 1: Install the following NuGet packages:
- ILRepak: https://www.nuget.org/packages/ILRepack/
- ILRepack.Lib.MSBuild.Task: https://www.nuget.org/packages/ILRepack.Lib.MSBuild.Task/
Step 2: Add an ILRepack.targets file to your project to configure ILRepack merge process. This specifies:
- The location of the assemblies to be merged:
- Target licensed assembly with which the SpAgent assemblies are to be merged
- SpAgent assemblies (typically done using an Sp.Agent.*.dll wildcard)
- The Union option to allow duplicate types for the Dotfuscator attribute in the SpAgent assemblies.
- Either the KeyContainer or KeyFile option if the merged assembly is to be signed
Step 3: Optionally add an ILRepack.Config.props file to your project to specify the location of the either the KeyFile or KeyContainer to be used to sign the merged assembly.
The following is a sample ILRepak.targets file that:
- Specifies the target assembly and SpAgent assemblies (all in the standard output directory) to be merged;
- Specifies the KeyFile option so that the merged assembly will be signed (the location of the KeyFile is specified in the ILRepack.Config.props file shown later below)
- Deletes all the SpAgent assemblies in the Output directory once they are merged with the target assembly.
<?xml version="1.0" encoding="utf-8" ?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Target Name="ILRepacker" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'"> <!-- Specify input assemblies to be merged (in standard output directory by default) --> <ItemGroup> <InputAssemblies Include="$(OutputPath)\*.exe" /> <InputAssemblies Include="$(OutputPath)\Sp.Agent*.dll" /> <AssembliesToDelete Include="$(OutDir)Sp.Agent.*" /> </ItemGroup> <!-- Specify KeyFile option if merged assembly is to be signed --> <!-- Specify Union option to support the duplicate Dotfuscator attribute in SpAgent assemblies -->
<ILRepack Parallel="true" DebugInfo="true" Union="true" AllowDuplicateResources="false" InputAssemblies="@(InputAssemblies)" TargetKind="SameAsPrimaryAssembly" KeyFile="$(KeyFile)" OutputFile="$(OutputPath)$(TargetName)$(TargetExt)" /> <Message Text="Deleting SpAgent DLLs in output folder $(OutDir) -> @(AssembliesToDelete)"/> <Delete Files="@(AssembliesToDelete)"/> </Target> </Project>
You can specify ILRepack configuration properties in the ILRepack.targets file. Alternatively you may specify these in an ILRepack.config.props file added to your project.
The following is a sample ILRepak.Config.Props file that specifies the KeyFile to be used when signing the final merged assembly.
<?xml version="1.0" encoding="utf-8" ?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <KeyFile>$(ProjectDir)MergeSigningKey.snk</KeyFile> </PropertyGroup> </Project>