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

Added type renamming and custom resource loader to handle merged satellite assemblies

Open PedroMGMendes opened this issue 4 years ago • 1 comments

Hi,

Had been working in a problem where ILRepack was a perfect fit, so thanks for making it available.

Although everything was working fine, there were two things i needed that weren't available so i added them, maybe it can be useful to others, hence the pull request.

Don't know if i should have or not created an issue first, as i don't have any issue to report.

Added support for type renaming/mapping

Description

Renames all types that match a given regular expression and replaces then by a specified value.

This is useful when using more than one merged assembly/clientLib in any given program, and the merged assemblies shared the same dependency but in different versions, thus avoiding the namespace/types clash.

The file must contains one regex per line followed by the new value. The Regex and the new value must be separated by a tab char ['\t'].

Sample lines:

^(Microsoft) MicroSft ^(NewtonSoft) Ns

Usage

 /renameNameSpaces:<namespacestorenamefile>

Added support for retrieving resources from satellite assemblies

Although it is possible to merge the satellite assemblies, typically found on the build output folder in folders like '/es', '/pt', '/fr', merging them would not make them visible/usable to the System.Resources.ResourceManager.

A new step was added (AddCustomResourceManagerStep) that compiles and injects a custom resource manager that enables loading resources from merged satellite assemblies. This fallbacks to the original resource manager behavior if no resources are found by the custom resource manager.

The code for the custom resource manager can be found here or in the source code.

 /usecustomresourcemanager

Whats missing

Unit Tests...maybe someone else can add them.

Not sure but this might answer issues #6 - Feature request: namespace mapping when merging assemblies and #158 - il-repack doesn't work with localized satellite assemblies.

PedroMGMendes avatar Mar 04 '20 16:03 PedroMGMendes

I like the idea of custom resource manager! 👍

Using ILRepack to merge satellite resource assemblies and automatically replace the resource loaders in one step would be a great time saver. But perhaps it should be submitted as a separate pull request in order not to mix it with the unrelated type mapping feature.

Also, as far as I know, System.Resources.ResourceManager is not the only class used to retrieve localized resources. Controls and winforms use System.ComponentModel.ComponentResourceManager which can be replaced with something like this.

yallie avatar Mar 04 '20 18:03 yallie

IL Metadata reshaping, like renames, could be done with already existing tools like Fody.

In my merged apps, I load a custom ResourceManager from the Main() method on application launch. It would be nice to have it done by ILRepack, but I don't like the current PR approach with C# source code compilation and IL copying.

deniszykov avatar Jan 06 '24 11:01 deniszykov

Agreed, this feels more like a feature for an orthogonal tool, such as a Fody weaver. You could run the namespace renamer externally to ILRepack, either on the inputs before calling ILRepack or on the output after calling ILRepack.

But let's keep ILRepack to do one thing and do it well: take multiple assemblies and merge them into one.

KirillOsenkov avatar Jan 07 '24 02:01 KirillOsenkov