'ILRepack (ILRepack.MSBuild.Task) unable to use Internalize when using wildcards

I am doing a proof of concept to understand how ILRepack (ILRepack.MSBuild.Task) works.

With this configuration, I am able to create a single merged dll, with ClassLibrary1, AutoMapper and Newtonsoft.Json internalized correctly:

 <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
<ItemGroup>
  <InputAssemblies Include="$(OutputPath)\ClassLibrary2.dll" />
  <InputAssemblies Include="$(OutputPath)\ClassLibrary1.dll" />
  <InputAssemblies Include="$(OutputPath)\AutoMapper.dll" />
  <InputAssemblies Include="$(OutputPath)\Newtonsoft.Json.dll" />
</ItemGroup>
<ItemGroup>
  <!-- Must be a fully qualified name -->
  <DoNotInternalizeAssemblies Include="ClassLibrary2" />
</ItemGroup>
<ILRepack Parallel="true" Internalize="true" InternalizeExclude="@(DoNotInternalizeAssemblies)" InputAssemblies="@(InputAssemblies)" TargetKind="Dll" OutputFile="$(OutputPath)\$(AssemblyName).dll" />

However, when I am trying to use wildcards, internalize don't works:

 <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
<ItemGroup>
  <InputAssemblies Include="$(OutputPath)\*.dll" />
</ItemGroup>
<ItemGroup>
  <!-- Must be a fully qualified name -->
  <DoNotInternalizeAssemblies Include="ClassLibrary2" />
</ItemGroup>
<ILRepack Parallel="true" Internalize="true" InternalizeExclude="@(DoNotInternalizeAssemblies)" InputAssemblies="@(InputAssemblies)" TargetKind="Dll" OutputFile="$(OutputPath)\$(AssemblyName).dll" />

Any idea why this is happening?

EDIT: Looks like the wildcards reorders the assemblies. Automapper is not internalized (because become the primary assembly), but all the others are (except ClassLibrary2, I suppose the DoNotInternalizeAssemblies does it's job)



Solution 1:[1]

It may have been added over time. You can specify WilcardInputAssemblies="true".

From ILRepack.MSBuild.Task:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="ILRepack.MSBuild.Task" Version="2.0.1" />
</ItemGroup>

<Target Name="ILRepack" AfterTargets="Build">

    <PropertyGroup>
        <WorkingDirectory>$(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework)</WorkingDirectory>
    </PropertyGroup>

    <ILRepack 
        OutputType="$(OutputType)" 
        MainAssembly="$(AssemblyName).dll" 
        OutputAssembly="$(AssemblyName).dll" 
        InputAssemblies="$(WorkingDirectory)\*.dll" 
        WilcardInputAssemblies="true"
        WorkingDirectory="$(WorkingDirectory)" />

</Target>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Natan