ILMerge DLL: Assembly not merged in correctly, still listed as an external reference

I had to use the /closed argument. According to the official docs:

Closed

When this is set before calling Merge, then the "transitive closure" of the input assemblies is computed and added to the list of input assemblies. An assembly is considered part of the transitive closure if it is referenced, either directly or indirectly, from one of the originally specified input assemblies and it has an external reference to one of the input assemblies, or one of the assemblies that has such a reference. Complicated, but that is life...


I got a similar error message when trying to publish a web app that merged all outputs to a single assembly:

An error occurred when merging assemblies: ILMerge.Merge: The target assembly lists itself as an external reference.

This happens if the assembly name you are merging to matches the assembly name of the web application under Properties > Application. Changing the output assembly name should fix it.