icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
21.34k stars 3.34k forks source link

`ilspycmd` to support the option for omitting token export #3206

Closed RaenonX closed 1 month ago

RaenonX commented 4 months ago

Is your feature request related to a problem? Please describe.

I am tracking the metadata change because of version bump of a DLL. I am not interested in the token address of these methods. However, the token/addresses of these metadata seems always getting exported.

Consulted both the help of ilspycmd at v8.2.0.7535 and https://www.nuget.org/packages/ilspycmd/8.2.0.7535, but doesn't seem like I have any option to remove this token export.

Since any update could cause a massive shift on these tokens, it will generate tons of useless diff, which contains token change and nothing else.

Describe the solution you'd like

A --no-token option should be enough.

Additional context

image

siegfriedpammer commented 1 month ago

It does not make sense to add a --no-token option, simply because the attribute you are seeing in your code is not a standardized custom attribute or pseudo attribute (like FieldOffset for example).

A possible solution would be to add something like a --omit-attribute Fully.Qualified.NameOf.Attribute option to filter certain custom attributes from the output, but where do we stop? The next person wants to only remove attributes from certain methods... how many options are we going to add?

There are two easier solutions: 1) Use the ICSharpCode.Decompiler package directly to decompile the code in question and add your own IAstTransform to the decompiler pipeline, just like we do in our unit tests, see https://github.com/icsharpcode/ILSpy/blob/master/ICSharpCode.Decompiler.Tests/Helpers/RemoveCompilerAttribute.cs 2) Use a simple regex to filter out those lines, tools like WinMerge let you even specify such filters/regexes on the fly without having to post-process the files yourself. A possible regex would be something like ^\s*\[Token\(Token\s*=\s*"0x[A-Fa-f0-9]{1,8}"\)\]$.

Hope this helps!