Is it possible to Add/Remove/Change an embedded resource in .NET DLL?

后端 未结 3 1540
后悔当初
后悔当初 2020-12-05 05:18

Is it possible to add/remove/change an embedded resource in a .NET DLL after it has been compiled? If so, how is this done, and are there any gotchas?

Edit:<

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 05:52

    There's no way to do this in managed code. Once a resource has been embedded it becomes part of the assembly just like the compiled MSIL code is.

    However, you could do this manually, like suggested by Lucero, by disassembling the DLL into a text file using ildasm, removing the resource using a text editor, and finally reassembling the DLL using ilasm.

    Here's an example using a DLL with a single embedded text file:

    1) Decompile the DLL into MSIL:

    ildasm MyLibrary.dll /out=MyLibrary.il
    

    2) Open the resulting MyLibrary.il file and remove the .mresource section:

    .mresource public MyLibrary.MyResource.txt
    {
      // Offset: 0x00000000 Length: 0x0000000F
      // WARNING: managed resource file MyLibrary.MyResource.txt created
    }
    

    3) Reassemble the DLL from the modified MyLibrary.il file:

    ilasm MyLibrary.il /dll
    

提交回复
热议问题