以编程方式将资源嵌入.NET程序集中 [英] 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程序集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文