gpt4 book ai didi

c# - 以编程方式将资源嵌入 .NET 程序集中

转载 作者:太空狗 更新时间:2023-10-29 20:12:13 26 4
gpt4 key购买 nike

我有一个已编译的 .NET 程序集,其中嵌入了一个特定的资源文件(名为“Script.xml”)。我需要以编程方式将其更改为另一个。

这是否可以在不从源代码重新编译的情况下完成?

目前,我正在搜索我知道在文件中的文本,而且效果很好。但是我需要为另一个项目做这件事,我不知道资源文件的任何内容,我需要找到另一种方法。

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

关于c# - 以编程方式将资源嵌入 .NET 程序集中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1107912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com