Академический Документы
Профессиональный Документы
Культура Документы
Discuss Assemblies Create Assemblies Private and Shared Assembly Discuss Versioning & Reflection Explain the structure of an assembly Explain Modules Work with Resource files Discuss the global assembly cache Create & Install shared assemblies Discuss versioning
Assemblies
An assembly is a means of reusing the code. An assembly consists of:
Set of Types and Resources Manifest
Manifest
The manifest of an assembly contains:
Identity of an assembly
Creating Assemblies
The following command creates an assembly from one or more source files:
The following command creates an assembly called array.dll from the array1.cs file:
Creating Executables
The following command creates an executable by compiling the source file using the /target:exe switch: The following command creates an executable array.exe from the array1.cs file:
Referencing an Assembly
To reference an assembly, add the /reference switch while creating the executable:
The following command creates an executable called array.exe from the source file array1.cs while referencing an assembly called array2.dll:
Namespaces
Provides a logical distribution of code
Avoids naming conflicts. Elements are designed to help us organize our code. Reduces complexity when the code is to be reused for some other application.
mechanism
Not a runtime entity Provides a logical
mechanism
A runtime entity
Provides a physical
structure to the names of structure to the runtime components of an source code elements executable
Assembly 2
Assembly 1
Versioning
All assemblies must have a version number. The following sequence is also available in some books Major Minor Build Revision
The DLL file needed to be upgraded by overwriting the existing DLL file.
Now, Windows 2000 operating system is capable of loading two assemblies with the same name but different version numbers.
Reflections (1)
Retrieves information about an object at runtime. The Type class is the base of all reflection information for an object. Two methods to get the Type object:
typeof()
GetType()
Reflections (2)
continued
Reflections (3)
continued
Output:
Reflections (4)
Table showing methods of the Type object
Assembly Structure
Every assembly has a predefined structure
.NET metadata can be thought of as a collection of information existing in binary format Metadata is a superset of older technologies such as type libraries Metadata and IDL files Type metadata describes the data present in the assemblyType type and its This metadata contains a declaration for every data type and members. It is a specification of the types declared and methods implemented in the assembly .NET compilers compile source code into an intermediate language called MSIL (Microsoft Intermediate Language). It is this MSIL that the MSIL CLR understands The MSIL is stored as a part of the Code assembly Resources are nothing but files required while developing the Resources application For example, the JPG file for the logo of your company. These resources can exist as a part of the .NET assembly or as a separate file
Assembly
Metadata
This command will generate a module file called MySource.netmodule Once a module is generated it can be made a part of any other assembly
The .NET SDK provides us with yet another tool called the IL Disassembler
IL Disassembler
This tool can be used to view the content of assemblies
and manifests
IL Disassembler (Cont.)
The Key identifies the resource by name, and the value refers to the resource, as in a hash table
Resgen Utility
The Resgen.exe utility comes along with the .NET framework SDK This utility is used to create resource files This command will create a file called
addr.resources
The resgen utility can also create XML-based resource file (.resX
ResourceWriter Class
Using the ResourceWriter class of the .NET BCL, we can add picture files to an assembly Using this class, you can add up to 2 GB of resources The AddResource() method is used to add resources.
Example
using System; using System.Resources; using System.Drawing; namespace AdvanceDotNet { class AacEx1 { [STAThread] static void Main(string[] args) { ResourceWriter ResW = new ResourceWriter("addr.resources"); using(Image logo = Image.FromFile("Bahria.jpg")) { ResW.AddResource("BahriaLogo", logo); ResW.AddResource("Description", "Bahria Corporate Logo"); ResW.Close(); } } }}
Cont.
Using defining the scope at the end of which an
Picture Box
Label
Cont
as1 is of assembly type and holds the reference to the
executing assembly Creating the object of ResourceManager class by passing two parameters the first is the root name of the resource and second is assembly object that hold the reference
Viewing GAC
The files in the GAC can be viewed using
manipulate, delete and view assemblies Can be used to install, uninstall and list assemblies on the GAC using the command line
/upre
Shared Assemblies
An assembly needs to be shared for it to be used by
various applications There should be no naming clashes with other assemblies To enable this, the assembly should have a unique identifier The Strong Name (sn.exe) utility is provided
take
Installing an Assembly
To install this signed assembly on the GAC we will use
gacutil.exe
Versioning
Versioning comes into picture when there is an
Version Compatibility
Change In Major Number or Minor Number Compatibility
Revision Number
Build Number
Compiling the above assembly will result in the version of the assembly being changed