Monday, May 21, 2007

Structure Of Assemblies

An assembly contains the executable code for a program or class library, along with the metadata (data describing other data), which enables other programs to look up classes, methods, and properties of the objects defined within the assembly.
The metadata acts in two ways:
· As a table of contents, describing what is contained inside the assembly
· As a bibliography describing references to data outside the assembly

Single file .NET assemblies have the following general format:
· Manifest (Assembly Metadata) à references to other assemblies
· Type of Metadata
· MSIL Code
· Resources (if present)

Define Manifest?
A manifest contains metadata describing the name, resources, type and version of the assembly as well as dependencies upon other assemblies. The manifest makes an assembly self-describing, easier to deploy, and not bound to a particular system because of strong data in Windows registry.
The manifest is also called the assembly metadata.
The manifest is the heart of the self-description built into .NET assemblies.

The files that contain executable code are called modules; these contain type metadata and MSIL code.
Resource files contain non-executable code such as images, icons, or message files.


What is the tool used to view the contents of an assembly?
The tool you can use to view the contents of an assembly is Ildasm, the .NET Framework Intermediate Language Disassembler tool. This is a handy tool for viewing and understanding the internal structure of assemblies.

How do you execute Ildasm from the VS Command Line?
· The quickest way to execute Ildasm is to go the start -> All Programs à MS VS 2005 à VS Tools à VS Command Prompt and simply enter Ildasm at the command prompt.
· Another way to execute Ildasm is to add it as an external tool to the VS 2005 development environment; this makes it easier to go back and execute it again without having to leave VS 2005. To do this, go to the Tools menu à External Tools and click Add button in this dialog. …..

Define Assembly Attributes?
Assembly attributes are values that provide information about an assembly. The attributes are divided into the following sets of information:
· Assembly identity attributes.
· Informational attributes.
· Assembly manifest attributes.
· Strong name attributes.

What is AssemblyInfo.cs?
AssemblyInfo.cs is used to set properties of the assembly in the manifest. Double-click on the file to open it and look at the contents.
Each of the statements in square brackets that looks like [assembly: Assembly….] is an attribute, a special syntax in C#.

What is Assembly Culture?
The line following the company and trademark attributes is the AssemblyCulture attribute:
[assembly: AssemblyCulture(“”)].
This sets the national language used for this assembly (English, French, Chinese, and so on) and if it is specified it is a special abbreviation following an international standard.
More information can be found in the System.Glbalization namespace.

Note: you don’t need to set the culture unless you’re distributing different language versions of a component. If doing this then the .NET runtime will automatically search for the version of your assembly that matches the current culture.

For Example: in France you display the French message (using your French message resources and/or code). You mark the appropriate assembly with the correct culture attribute for this to happen.

What is Assembly Version Numbers?
The line following the culture attribute is the AssemblyVersion attribute.
[assembly: AssemblyVersion(“1.0”)]
The version for a .NET assembly has four parts:
Major Version . Minor Version . Build Number . Revision
The BuildNumber and the Revision number in the Assembly Version takes the versioning to a finer level of detail.

What is the Build Number in the AssemblyVersion?
The Build Number indicates which build of the assembly this is; the build number will change every time the assembly is rebuilt. Two assemblies with the same major/minor version number and a differing build number may or may not be compatible.

What is the Revision Number in the AssemblyVersion?
The revision number goes one level deeper and is designed to be used for a patch or a “hot fix” to an assembly that is exactly same as the build number; except for this one bug fix.

VS 2005 assigns version numbers automatically as projects are built, depending on what information is set in the AssemblyVersion attribute.

What is AssemblyVersion attribute?
Within the AssemblyInfo.cs file created by VS 2005, the version number is set with the AssemblyVersion Attribute:
[assembly: AssemblyVersion(“1.0.*)]
The AssemblyVersion attribute allows an asterisk(*) to be specified for the last two parts of the version number. This directs VS 2005 to set the build and revision numbers automatically.

Note: You can also specify the asterisk just for the revision number (as in 1.1.1.*) but not the major and minor version numbers (1.* is not allowed).

Note: You can directly set all the parts of the version by specifying a specific number instead of the asterisk:
[assembly: AssemblyVersion(“1.0.1.2”)]
This will force VS 2005 to produce an assembly wit this specific major, minor, build, and revision number.

How do check the version numbers or the assembly’s version attributes?
Use the Ildasm to check the full version number. For ex, if an end user reports a bug, you can compare the version of the assembly on your computer and the one installed on the end user’s computer. You can tell exactly which version that user has; with the revision and build numbers.

What does the manifest of an assembly contains?
The manifest of an assembly contains the version number of the current assembly as well as the version numbers of the referenced external assemblies.

What is the Version Compatibility?
The .NET runtime checks version numbers when loading assemblies to determine version compatibility. This is done only for shared assemblies.
When the .NET runtime loads a referenced assembly, it checks the version in that assembly’s manifest and compares it to the version stored in the reference to make sure the versions are compatible.
If the assemblies have different major or minor version numbers, they are assumed to be incompatible, and the reference assembly will not load.

What is side-by-side execution?
What if you have program A that uses Shapes 1.0 and program B that uses Shapes 1.1 on the same system?
This is actually taken care of in the .NET runtime; there is a feature called side-by-side execution, which enables Shapes 1.0 and Shapes 1.1 to both be installed on the same computer and each to be available to the programs that need that version.

No comments: