I want to “merge” (or “pack”) some .NET assemblies into one.
To achieve this I am trying “ILRepack”.
I am referencing the nuget package ‘ILRepack.MSBuild.Task’ (version 2.0.13) in a class library called “MyCombinedClassLibrary”. When I build this project “MyCombinedClassLibrary” the assemblies “MyClassLibrary1”, “MyClassLibrary2” and “MyClassLibrary3” will be successfully “merged” into one “MyCombinedClassLibrary.dll”. Works as expected.
Now when I am referencing this combined assembly in another project, like a MSTest project, I can not access the classes of the merged assemblies like “MyClassLibrary1.MyClass”.
I have already checked “MyCombinedClassLibrary.dll” with dotPeek. The tool shows that the expected classes are part of the combined dll – and they are public, too. So I don’t get it what I am doing wrong here.
MyCombinedClassLibrary.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- PACKAGE REFERENCES -->
<ItemGroup>
<PackageReference Include="ILRepack.MSBuild.Task" Version="2.0.13" />
</ItemGroup>
<!-- ILREPACK CONFIGURATION -->
<Target Name="ILRepack" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">
<PropertyGroup>
<WorkingDirectory>$(MSBuildThisFileDirectory)bin$(Configuration)</WorkingDirectory>
</PropertyGroup>
<ItemGroup>
<InputAssemblies Include="MyClassLibrary1.dll" />
<InputAssemblies Include="MyClassLibrary2.dll" />
<InputAssemblies Include="MyClassLibrary3.dll" />
</ItemGroup>
<ItemGroup>
<InternalizeExcludeAssemblies Include="MyClassLibrary1" />
<InternalizeExcludeAssemblies Include="MyClassLibrary2" />
<InternalizeExcludeAssemblies Include="MyClassLibrary3" />
</ItemGroup>
<Message Text="MERGING: @(InputAssemblies->'%(Filename)') into $(AssemblyName)" Importance="High" />
<ILRepack OutputType="$(OutputType)" MainAssembly="$(AssemblyName).dll" OutputAssembly="$(AssemblyName).dll" InputAssemblies="@(InputAssemblies)" InternalizeExcludeAssemblies="@(InternalizeExcludeAssemblies)" WorkingDirectory="$(WorkingDirectory)" />
</Target>
</Project>
Screenshot of my projects:
projects
murphysto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.