gluck / il-repack

Open-source alternative to ILMerge
Apache License 2.0
1.16k stars 214 forks source link

Option to remove all non-referenced members from output assembly #309

Closed i00 closed 6 months ago

i00 commented 2 years ago

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

AlanHauge-Interacoustics commented 1 year ago

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.

lextm commented 1 year ago

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.

deniszykov commented 1 year ago

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

KirillOsenkov commented 8 months ago

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 commented 8 months ago

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

KirillOsenkov commented 6 months ago

.NET now has an official tool that implements trimming (ILLink): https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-8-0

I think we're unlikely to ever implement trimming ourselves in ILRepack. You can trim the output of ILRepack using ILLink in a separate step.