是否可以在.NET DLL中添加/删除/更改嵌入式资源? [英] Is it possible to Add/Remove/Change an embedded resource in .NET DLL?
问题描述
是否可以在编译之后添加/删除/更改.NET DLL中的嵌入式资源?如果是这样,这是怎么做的,有没有问题?
编辑:
我想手动执行此操作,但最终会自动通过后构建事件中的脚本。 strong>无法在托管代码中执行此操作。一旦资源被嵌入,它就像编译的MSIL代码一样成为程序集的一部分。
但是,您可以手动执行像建议通过Lucero ,通过使用 ildasm ,使用文本编辑器删除资源,最后使用 ilasm 。
下面是一个使用单个嵌入文本文件的DLL的示例:
1)将DLL解压缩为MSIL:
ildasm MyLibrary。 dll /out=MyLibrary.il
2)打开结果 MyLibrary.il
文件和删除e .mresource
部分:
.mresource public MyLibrary.MyResource。 txt
{
//偏移:0x00000000长度:0x0000000F
//警告:托管资源文件MyLibrary.MyResource.txt创建
}
3)从修改后的 MyLibrary.il
文件中重新组装DLL:
ilasm MyLibrary.il / dll
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:
I would like to do this manually, but eventually automatically through a script in the post-build event.
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
这篇关于是否可以在.NET DLL中添加/删除/更改嵌入式资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!