Search code examples
c#resourcesembedded-resourcedynamicresource

Dynamically change resource of executable


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?


Solution

  • 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:

    AppDomain.CurrentDomain.SetData("CONFIG_FILE", "C:\Path\To\File.config");
    

    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(....).