是否可以在 .NET DLL 中添加/删除/更改嵌入资源? [英] Is it possible to Add/Remove/Change an embedded resource in .NET DLL?

查看:15
本文介绍了是否可以在 .NET DLL 中添加/删除/更改嵌入资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 .NET 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?

我想手动执行此操作,但最终会通过构建后事件中的脚本自动执行.

I would like to do this manually, but eventually automatically through a script in the post-build event.

推荐答案

在托管代码中无法做到这一点.一旦资源被嵌入,它就会成为程序集的一部分,就像编译后的 MSIL 代码一样.

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.

但是,您可以手动执行此操作,例如 Lucero 建议,通过使用 ildasm,使用文本编辑器删除资源,最后使用 ilasm.

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.

以下是使用带有单个嵌入文本文件的 DLL 的示例:

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

1) 将 DLL 反编译为 MSIL:

1) Decompile the DLL into MSIL:

ildasm MyLibrary.dll /out=MyLibrary.il

2) 打开生成的 MyLibrary.il 文件并删除 .mresource 部分:

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) 从修改后的 MyLibrary.il 文件中重新组装 DLL:

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

ilasm MyLibrary.il /dll

这篇关于是否可以在 .NET DLL 中添加/删除/更改嵌入资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆