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

编程入门 行业动态 更新时间:2024-10-26 05:26:55
本文介绍了以编程方式将资源嵌入.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程序集中

本文发布于:2023-11-09 10:12:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572100.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   程序   资源   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!