MSBuild task for ILRepack which is an open-source alternative to ILMerge.
Install-Package ILRepack.Lib.MSBuild.Task
- MSBuild
You need to install the NuGet package to merge all your project dependencies. If you want to customize the process, then
you can create a file named ILRepack.targets in your project folder. You can create it like shown below.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- ILRepack -->
<Target Name="ILRepacker" AfterTargets="Build" Condition="'$(Configuration)' == 'Release' and '$(IsCrossTargetingBuild)' != 'true'">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)\ExampleAssemblyToMerge1.dll" />
<InputAssemblies Include="$(OutputPath)\ExampleAssemblyToMerge2.dll" />
<InputAssemblies Include="$(OutputPath)\ExampleAssemblyToMerge3.dll" />
</ItemGroup>
<ItemGroup>
<!-- Must be a fully qualified name -->
<DoNotInternalizeAssemblies Include="ExampleAssemblyToMerge3" />
</ItemGroup>
<ILRepack
Parallel="true"
Internalize="true"
InternalizeExclude="@(DoNotInternalizeAssemblies)"
InputAssemblies="@(InputAssemblies)"
TargetKind="Dll"
OutputFile="$(OutputPath)\$(AssemblyName).dll"
/>
</Target>
<!-- /ILRepack -->
</Project>You need to create the ILRepack.Config.props file in your project folder to configure the behavior of
ILRepack.Lib.MSBuild.Task.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
</PropertyGroup>
</Project>You can specify the following options inside the <PropertyGroup> element to configure the behavior of the ILRepack
task.
If you don't want to add ILRepack.targets file in your project folder, then you can specify your custom targets file
path as shown below.
<ILRepackTargetsFile>$(SolutionDir)ILRepack.targets</ILRepackTargetsFile>You can specify the path of the SNK file you want to use for signing your assembly as shown below. This configuration option only applies if you are using the default targets file provided in the NuGet package.
<KeyFile>$(ProjectDir)ILRepack.snk</KeyFile>If you are using the default targets file, then you may notice that it clears the Output directory after merging dependencies. You can turn this functionality off by setting ClearOutputDirectory to False as shown below.
<ClearOutputDirectory>False</ClearOutputDirectory>