Create exe copy with another resource at runtime

We would like to offer our client the opportunity to create customized exes, based on ours, for our clients.

i.e., basically, the ability to make an exe copy with another xml configuration file built into it. โ€œInclude it in the installationโ€ is not an option - we want it to look as if it was done for our client clients.

I'm currently going to write a dll at runtime, including a resource (using AssemblyBuilder), and then call ILMerge to insert it into the final exe, but it's a little more hacky than I would like.

So, this is a tall question, but it might be worth asking: is there a .NET library that allows you to modify .NET exe resources that can avoid the DLL bit that stores the resource embedded by ILMerge?

Or, conversely, is there a better approach to this that still meets the stated goals?

+6
source share
2 answers

It sounds like a lot of work to replace it as soon as it is already compiled. I would do this with a script assembly, parameter, and different resource files.

+2
source

Although this is not the approach I would take with this problem, there is a library that allows you to modify the embedded resources of the compiled executable, Cecil .

Embedding a resource using Cecil:

namespace inclusion:

using Mono.Cecil; // supports both net and mono 

Resource Attachment:

  static void Main(string[] args) { string pathToExecutable = "Target.exe"; byte[] encoding = Encoding.Unicode.GetBytes("<Data><!-- data goes here --></Data>"); var resource = new EmbeddedResource( "ConfigurationFile", ManifestResourceAttributes.Private, encoding); var asm = AssemblyDefinition.ReadAssembly(pathToExecutable); asm.Modules.FirstOrDefault().Resources.Add(resource); asm.Write(pathToExecutable); } 
0
source

Source: https://habr.com/ru/post/911092/


All Articles