Saturday, November 6, 2010

Resource Files in .NET Assembly


In general, manifest is another set of metadata tables that basically contain the names of the files that are part of the assembly. It contains 4 metadata tables namely AssemblyDef, ManifestResourceDef, FileDef and ExportedTypesDef.

You can add a file as a resource to the assembly by using the /embed[resource] switch. This switch takes a file (any file) and embeds the file’s contents into the resulting PE file. The manifest’s ManifestResourceDef table is updated to reflect the existence of the resources.

/link[resource] switch updates the manifest’s ManifestResourceDef and FileDef tables, indicating that the resource exists and identifying which of the assembly’s files contains it. The resource file is not embedded into the assembly PE file; it remains separate and must be packaged and deployed with the other assembly files.

On adding resource files in any .NET assembly, C# compiler’s /resource switch embeds the specified resource file into the resulting assembly PE file, updating the ManifestResourceDef table. The compiler’s /linkresource switch adds an entry to the ManifestResourceDef and the FileDef manifest tables to refer to a stand-alone resource file.

No comments:

Post a Comment