views:

490

answers:

3

Hello. Given: - an assembly (e.g. "SomeLib.dll") - a text file (e.g. "myconfig.xml")

I need to embed the file myconfig.xml into the existing assembly SomeLib.dll

Please consider before pressing "Answer": I know about resources embeding during compile (csc.exe .. /embedresource:file ... ).

The thing is that I need to embed a resource after assembly has created.

Is it possible?

I also know about ILMerge. But havn't found how it could help.

A: 

Your going to need to resign the assembly after adding the resource. The whole point of assembly signing is to prevent people from modifying the contents of an assembly without being able to tell it was modified. You can use signcode.exe, http://msdn.microsoft.com/en-us/library/9sh96ycy(VS.80).aspx to resign the assembly after adding the resource, assuming you have the proper certificates.

LanceSc
Resigning an assembly is not an issue. ILMerge does that fine.The question was how to add a resource to existing assembly withing recompiling all sources.
Shrike
A: 

The Assembly Linker tool can be used to combine modules and resources into a signed assembly. However, I have not been able to find a way to use an existing assembly as input.

> al.exe SomeLib.module /out:SomeLib.dll /keyfile:SomeLib.snk /embed:myconfig.xml
Emperor XLII
So do I. I looked at al.exe and didn't found how it could help. Only if to find a way to get *.module from existing .dll... :-/
Shrike
+1  A: 

You can use Cecil for this: load an assembly, add a resource, save to an assembly.

Tommy Carlier
Any chance you could share the code you ended up using? I played around with Cecil but couldn't get it to actually save the resources. Thanks.
BarrettJ