动态更改可执行文件的资源
我有两个 C# 可执行文件:patcher.exe 和 Generator.exe。
现在 patcher.exe 有一个 .Net 资源“config.dat”,但它是空的。
我想要的是generator.exe可以更改(完全覆盖)修补程序的config.dat。这样我们就可以将具有不同配置的修补程序分发给不同的人,而他们实际上并不了解内部处理,也不知道 config.dat 是如何生成的。
那么如何从generator.exe动态更改patcher.exe的.Net资源呢?
I have two C# executables, patcher.exe, and generator.exe.
Now patcher.exe has a .Net resource 'config.dat', and it's empty.
What I want is that generator.exe, can change (completely overwrite) the config.dat of the patcher. This is so that we can distribute patchers with different configuration to different people, without them actually knowing much about the internal processing, nor knowing how the config.dat is generated.
So how to dynamically change the .Net resource of patcher.exe from generator.exe?
您确定在运行时编辑嵌入资源就是您想要的吗?因为它需要重新编译。
听起来,您可以通过 app.config 指定您希望在运行时以编程方式使用的应用程序域来实现这种配置灵活性。这可以通过以下方式实现:
或者为用户创建自定义配置部分并将这些包括在内。
最后,您可能还想研究 Satellite 程序集,其中 MSDN 上的示例涉及具有多种不同语言翻译的应用程序。 这里
看来我很抱歉误解了您想要实现的目标。如果我理解正确的话,您似乎想要按照 这篇文章 的思路实现一些目标。有关该方法的信息(诚然,示例不是 C# 代码)是 MSDN,但这给出了逻辑。然后您可以使用 UpdateResource(....)。
You sure editing the embedded resource at runtime is what you're after? As it would require a recompile.
As from the sounds of it you could achieve this configuration flexibility through the app.config by specifying the application domain you wish to use programmatically at runtime. This can be achieved by:
Or by creating custom configuration sections for users and have these included.
Finally you may also want to look into Satellite assemblies with the example on MSDN referring to an application with several different language translations. Here
Right apologies it seems I misunderstood what you were trying to achieve. If I understand correctly it looks like you want to achieve something along the lines of this post. More information on the method (admittedly the sample is not C# code) is on the MSDN, but this gives the logic. You can then use UpdateResource(....).