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 程序集中


基础教程推荐
- 从 C# 控制相机设备 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 如果条件可以为空 2022-01-01
- 将数据集转换为列表 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01