il-repack icon indicating copy to clipboard operation
il-repack copied to clipboard

Support for remapping references

Open richard-fine opened this issue 7 years ago • 4 comments

I've got a bunch of assemblies {A1.dll, A2.dll, A3.dll...} and corresponding test assemblies {A1.Tests.dll, A2.Tests.dll, A3.Tests.dll...} I'm merging the main assemblies together into a single A.dll for distribution, and now I'd like to merge all the tests together as well into A.Tests.dll to distribute alongside it.

However, because the all of the Tests.dll assemblies were originally built prior to stuff being merged, the resulting A.Tests.dll assembly still references all the pre-merged {A1.dll, A2.dll, A3.dll, ...} assemblies. This is no good...

I could recompile the A1.Tests.dll... dlls from scratch with different references, but it's not great to redo all that compilation work just to change a reference. I could also write a custom tool using Cecil to edit the references, but that again seems inefficient considering that ILRepack is already doing most of that work.

So I'm wondering about having some kind of /remapRef:from:to or /remapRefsFile:file command-line parameter, which my build code could use to specify for each of the A1.dll, "remap this to the merged A.dll".

What do you think?

richard-fine avatar Aug 14 '18 07:08 richard-fine

Or perhaps more simply than generic reference rewriting: /alreadyMerged: which takes the output of a previous ILMerge run, loads all the types from it, and rewrites any references in the inputs that match the full names of those types to point at the new assembly.

richard-fine avatar Aug 14 '18 19:08 richard-fine

Did you ever find a workaround or tool to make this happen? This would be incredibly useful. I've not managed to find any simple solution short of manually hacking things up or building a tool to do same.

gjonespf avatar Oct 08 '19 20:10 gjonespf

Note that ILRepack creates/updates a resource in the merged assembly ILRepack.list that contains the list of pre-merge assemblies. Looks like maybe it could leverage that during the merge process of the tests assemblies, and resolve any missing reference towards a merged assembly of said reference. If it resolves this way only as a fallback, could even be the default behavior of ILRepack (better than failing the merge), feel free to work out a PR.

It still requires that the original (non-test) assembly was created with ILRepack, as ILMerge doesn't maintain that metadata.

gluck avatar Oct 09 '19 08:10 gluck

It is possible to avert problem by generating type forwarding assemblies in place of merged ones https://learn.microsoft.com/en-us/dotnet/standard/assembly/type-forwarding

But is big chunk of work to implement this feature, I'm not sure some one will make PR for it.

deniszykov avatar Jan 08 '24 14:01 deniszykov