Advanced - ILMerge / IL-Repack

Advanced topic here, asking around several places, figure I’d try here to see if any unity users have any expertise to share on the matter.

I have a lot of code that I compile into its own assembly/dll and bring into my unity projects and place in the ‘Plugins’ folder. Let’s call this ‘MyAssemb.dll’. And of course I have editor specific code, and lets call that ‘MyAssembEditor.dll’.

Today, I had to split these projects into 2. This means I get 4 dll’s in total now, 2 runtime, and 2 editor only. Let’s call these:

MyAssemb.Base.dll
MyAssemb.Extended.dll

MyAssembEditor.Base.dll
MyAssembEditor.Extended.dll

I can’t just drop these new dll’s into an existing project because all the serialized data in the project that happens to reference these dll’s won’t be able to find the appropriate scripts inside them. From what I can tell, it references the script by the file it’s in, and that file is referenced by a guid.

So I thought maybe I can just merge the dll’s that are built from these divided projects back into a single dll just like it was before I had to divide the project.

I got ILMerge to do this, and the runtime dll’s merged together perfectly fine! I bring that merged dll in, and everything works correctly, the scripts that are attached to GameObjects remain in tact. Lets call the merged dll’s:

MyAssemb.Merged.dll
MyAssembEditor.Merged.dll

Problem occurs when I merge the editor dll’s. The problem is that editor dlls reference the runtime dlls. The resulting merged dll still referenced the split runtime dlls. But only the merged runtime dlls are brought into unity. And I don’t know how to make ILMerge merge together the referenced assemblies inside it.

Basically MyAssembEditor.Merged.dll still references MyAssemb.Base.dll and MyAssemb.Extended.dll. But I only have MyAssemb.Merged.dll in the unity project.

I need to figure out a way to build these divided projects into a single dll, while maintaining the appropriate references between them.

So I’m taking it no one knows…

Darn.

So… I never got ILMerge or anything similar to work.

Instead what I did was wrote a program that would read in the .csproj files for the various projects that makeup the entire framework.

From that I’d determine what files are supposed to be compiled into each assembly, and create a whole new ‘proj’ file with all of them in one project as ‘Links’ (like if you had added the file to a project, but instead of copying it into the project, you link to it).

With that I can run MSBuild on these project files.

So I wrote a batch file that runs the program to merge all the projects into a single project. Then run MSBuild on it. And I tacked on a command to copy the resulting build into my Unity\Plugins folder so I can just double click the batch file and update everything in one go.