Description
An assembly is a reusable, versionable, self-describing deployment unit for types and resources. Assemblies are the fundamental units of deployment, and consist of collections of types and resources that are built to work together and form logical units of functionality.
An assembly consists of the following two logical elements:
The sets of types and resources that form some logical unit of functionality. A manifest, which is the metadata that describes how the types and resources of an assembly relate and what they depend on to work properly. The following information is captured in an assembly manifest:
Identity—
An assembly's identity includes its simple name (also called its weak name), a version number, an optional culture if the assembly contains localized resources, and an optional public key used to guarantee name uniqueness and to "protect" the name from unwanted reuse.
Contents—
Assemblies contain types and resources. The manifest lists the names of all the types and resources that are visible outside the assembly, along with information about where they can be found within the assembly.
Dependencies—
Each assembly explicitly describes other assemblies that it is dependent upon. Included in this dependency information is the version of each dependency that was present when the manifest was built and tested. In this way the "known good" configuration is recorded and can be reverted to in case of failures due to version mismatches.
Requested Permissions—
As an assembly is being built, the assembly records the set of permissions that the assembly requires to run.
[Note: For additional information about assemblies, see Partition II of the CLI Specification.]
Example
using System;
using System.Text;
using System.Reflection;
/// <summary>
/// This example shows how to generate ILDASM-like output for an assembly.
/// </summary>
public class AssemblySample
{
public static void Main()
{
Assembly assembly = Assembly.GetExecutingAssembly();
Console.WriteLine("ILDASM style output for '{0}'",
assembly.GetName().Name);
Console.WriteLine("---------------------------------------------");
Console.WriteLine("// Metadata version: {0}",
assembly.ImageRuntimeVersion);
foreach (AssemblyName refAssemblyName
in assembly.GetReferencedAssemblies())
{
Console.WriteLine(".assembly extern {0}", refAssemblyName.Name);
Console.WriteLine("{");
Console.WriteLine(" .publickeytoken = ({0})",
ByteArrayToHexString(refAssemblyName.GetPublicKeyToken()));
Console.WriteLine(" .ver {0}",
refAssemblyName.Version.ToString().Replace('.', ':'));
Console.WriteLine("}");
}
Console.WriteLine(".assembly {0}",assembly.GetName().Name);
Console.WriteLine("{");
foreach (Attribute attrib in assembly.GetCustomAttributes(false))
{
Console.WriteLine(" .custom instance {0}", attrib);
}
Console.WriteLine(" .hash algorithm {0}",
assembly.GetName().HashAlgorithm);
Console.WriteLine(" .ver {0}",
assembly.GetName().Version.ToString().Replace('.', ':'));
Console.WriteLine("}");
foreach (Module currentModule in assembly.GetModules())
{
Console.WriteLine(".module {0}", currentModule.Name);
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Press Enter to continue");
Console.ReadLine();
}//end main
private static string ByteArrayToHexString(byte[] values)
{
StringBuilder hexString = new StringBuilder();
foreach (byte b in values)
{
hexString.AppendFormat("{0:X}", b);
hexString.Append(' ');
}
return hexString.ToString();
}
}
The output is
ILDASM style output for 'Assembly'
---------------------------------------------
// Metadata version: v1.1.4322
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 1:0:5000:0
}
.assembly Assembly
{
.custom instance System.Diagnostics.DebuggableAttribute
.hash algorithm SHA1
.ver 0:0:0:0
}
.module Assembly.exe
Press Enter to continue
|