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

Option to remove all non-referenced members from output assembly

Open i00 opened this issue 2 years ago • 5 comments

It would be great to have an option to remove all items from an assembly that are non-referenced. .. With an option to exclude specified attribute names (allow for multiple) - I guess the obfuscation one should be respected by default IF no command line switch is passed in ... and another option to remove private & friend only (to allow for public libs)

Thanks

i00 avatar Mar 15 '22 05:03 i00

I vote for this!

There should be a way to exclude specific classes / methods, also to ensure InternalVisibleTo does not break (for example for unit tests). I'm not I'm a fan of attributing with ObfuscationAttribute, although it's a very simply solution (and I like those !). An exclusion based on (part of) the full name in configuration would be better in my mind.

This is a reasonable but unrealistic feature request for a small open source project of this size.

Tree shaking algorithm isn't simple, and even Microsoft works on this for years and takes several .NET Core releases to improve it.

lextm avatar Feb 14 '23 08:02 lextm

You can use Microsoft remake of monolinker (which is used in Unity and Blazor) for it.

deniszykov avatar Feb 14 '23 09:02 deniszykov

Agreed, you can use ILLink on the merged assembly after the fact to tree-shake it.

We do have a branch with a prototype of a linker here: https://github.com/gluck/il-repack/tree/linker

However it's 8 years old, and stale and I don't know what the state of it was.

KirillOsenkov avatar Jan 07 '24 02:01 KirillOsenkov

https://github.com/dotnet/core/blob/main/samples/linker-instructions.md

KirillOsenkov avatar Jan 07 '24 02:01 KirillOsenkov