ModuleBuilder::DefineManifestResource Method (String^, Stream^, ResourceAttributes)
Defines a binary large object (BLOB) that represents a manifest resource to be embedded in the dynamic assembly.
Assembly: mscorlib (in mscorlib.dll)
public: void DefineManifestResource( String^ name, Stream^ stream, ResourceAttributes attribute )
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.
This method allows you to embed a manifest resource BLOB into a dynamic assembly.
To embed a managed resource into the manifest module of a dynamic assembly or into a satellite module, use the ModuleBuilder::DefineResource method to get a resource writer, and use the ResourceWriter::AddResource method to add the resource.
To link a manifest resource BLOB into a dynamic assembly, use the AssemblyBuilder::AddResourceFile method to add the linked resource.
In addition, a single Win32 resource can be attached to an assembly by using the AssemblyBuilder::DefineUnmanagedResource method or the ModuleBuilder::DefineUnmanagedResource method. This resource does not appear in the assembly manifest.
The following example generates and saves a dynamic assembly named EmittedManifestResourceAssembly.exe, which contains an embedded unmanaged resource. The example creates the assembly, which consists of one module, and opens a memory stream to contain the unmanaged resource. The code then calls the method to define the resource.
You can use any kind of stream for your resource; for example, you can read the unmanaged binary data from a file.
The example defines a type in the dynamic module with a Main method, and generates MSIL for the method body. After the body for the Main method has been generated and the type has been created, the code example writes five bytes to the stream associated with the manifest resource. When the assembly is saved, the resource is appended to it.
After running the example, you can run the emitted assembly. The code in the emitted assembly's Main method reads the embedded manifest resource and prints the byte values to the console. You can use the Ildasm.exe (IL Disassembler) to view the information in the assembly manifest.
Available since 2.0
Available since 2.0