相关疑难解决方法(0)

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

我有一个嵌入了特定资源文件的编译.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();
Run Code Online (Sandbox Code Playgroud)

c# compiler-construction resources

7
推荐指数
1
解决办法
2247
查看次数

标签 统计

c# ×1

compiler-construction ×1

resources ×1