Programmatically embed resources in a .NET assembly(以编程方式将资源嵌入 .NET 程序集中)
问题描述
我有一个已编译的 .NET 程序集,其中嵌入了一个特定的资源文件(名为Script.xml").我需要以编程方式将其更改为另一个.
I have a compiled .NET assembly with a specific resource file embedded (named 'Script.xml'). I need to programmatically change it out for another.
不从源代码重新编译是否可以做到这一点?
Is this possible to do without recompiling from source?
目前,我搜索我知道文件中的文本,它运行良好.但是我需要为另一个我不知道资源文件的任何内容的项目这样做,我需要找到另一种方法.
Currently, I do a search for text I know is in the file and it works well. But I need to do it for another project where I don't know any of the contents of the resource file and I need to find another method.
FileStream exe = new FileStream(currentexe, FileMode.Open);
//find xml part of exefile
string find = "<?xml version="1.0"?>";
string lastchars = new string(' ', find.Length);
while (exe.CanRead) {
lastchars = lastchars.Substring(1) + (char)exe.ReadByte();
if (lastchars == find) {
exe.Seek(-find.Length, SeekOrigin.Current);
break;
}
}
//output serialized script
int bytenum = 0;
foreach (byte c in xml) {
if (c == 0) break;
exe.WriteByte(c);
bytenum++;
}
//clean out extra data
while (bytenum++ < ScriptFileSize) {
exe.WriteByte(0x20);
}
exe.Close();
推荐答案
您可以使用 Cecil
打开程序集并插入资源(我这样做).YMMV
You could use Cecil
to open the assembly and insert a resource (I do). YMMV
这篇关于以编程方式将资源嵌入 .NET 程序集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以编程方式将资源嵌入 .NET 程序集中


基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01