Dynamically creating satellite assemblies with embedded resources

G

Guest

I'd like to create a satellite assembly dynamically, embedding rather than
linking resource files. I know I can use the assembly linker (al.exe) to
embed a .resources file, but I'd like to do it programmatically, using
something like the AssemblyBuilder class.

This is the same question that Nick Carter asked before. I've pasted his
post below, it case it clarifies things for anyone.
------ Nick Cases original post -----
al.exe has a /embed switch which allows me to create an assembly and embed a
resource in it. I want to duplicate this behaviour using the AssemblyBuilder
class. AssemblyBuilder has two methods, AddResourceFile and DefineResource,
which allow me to add resources to an assembly but AFAICS the files which
are specified using these methods are simply referenced - they are not
embedded. The resulting assembly still needs the .resource file to be
present at runtime. How can I use AssemblyBuilder to add resources to an
assembly where the resources are embedded (i.e. they have their
ResourceLocation.Embedded and ResourceLocation.ContainedInManifestFile flags
set just like al.exe does when using the /embed switch) ?
 
N

Nick Carter

Notre,

The solution to this problem is to use ModuleBuilder.DefineResource to
define the resource. The resulting resource has the
ResourceLocation.Embedded and ResourceLocation.ContainedInManifestFile flags
set. AssemblyBuilder.DefineResource and AssemblyBuilder.AddResourceFile do
not set these flags.

Nick
 
N

Nick Carter

I suspect that this is a module naming problem. It looks as if your module
name is not the same as the assembly name. AssemblyBuilder.Save treats
modules differently when they have the same name as the assembly. Check the
documentation on AssemblyBuilder.Save for an explanation.

Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top