Emitting Resources with Reflection EmitÂ
Resources that are recorded in the assembly manifest can be managed resources or manifest resource blobs, and each of these can be included in the assembly either by linking or by embedding. All four scenarios are supported for dynamic assemblies.
To embed an unmanaged manifest resource blob into a module of an assembly, use the DefineManifestResource method of the ModuleBuilder class.
To embed a managed resource into the manifest module of a dynamic assembly, or into a satellite module, use the System.Reflection.Emit.ModuleBuilder.DefineResource method to get a resource writer, and the System.Resources.ResourceWriter.AddResource method to add the resource.
To link a managed resource into a dynamic assembly, use the System.Reflection.Emit.AssemblyBuilder.DefineResource method to get a resource writer, and use the System.Resources.ResourceWriter.AddResource method to add the resource.
To link a manifest resource blob into a dynamic assembly, use the System.Reflection.Emit.AssemblyBuilder.AddResourceFile method to add the linked resource.
In addition, a single Win32 resource can be attached to an assembly using the System.Reflection.Emit.AssemblyBuilder.DefineUnmanagedResource method or the System.Reflection.Emit.ModuleBuilder.DefineUnmanagedResource method. This resource does not appear in the assembly manifest.
An unmanaged version information resource can be added to a dynamic assembly using the System.Reflection.Emit.AssemblyBuilder.DefineVersionInfoResource method. DefineVersionInfoResource builds a version information resource using the properties of the AssemblyName class.