Assembly essence-assembly in-depth discussion: assembly structure and deployment

Source: Internet
Author: User
1. Assembly definition
In simple terms, assembly is a CLR-based, verbose, and self-described binary file. It should be noted that, although the Assembly file name in. NET Framework is also DLL or EXE, it is different from the traditional DLL. Most importantly, assembly is a self-describing file that contains a large amount of information describing its own content.

2. AssemblyProgramSet structure (Format)
Generally, an Assembly includes the following parts:
1,Header file information: Win32 header file + CLR header file (Win32 header file + CLR header file)
2. PencilCode(Pencil code)
3. Type metadata)
4,Assembly manifest)
5,Optional embedded resources (optional embemed resources)

The following describes the functions of each part:
1. Win32 header file and CLR header file
The Win32 header file contains the necessary information provided when assembly is loaded by windows. The header information indicates the type (console-based, Gui-based, or *. dll) that assembly will reside in Windows OS.
We can use the. net sdk tool dumpbin.exe/headers to view its header file.
CLR header file information defines multiple tags so that CLR can understand the Assembly layout. For example, these tags indicate the location of metadata and resources, the Runtime Library version built by assembly, and publickey (optional.
We can use the. net sdk tool dumpbin.exe/clrheader to view its header file.

2. Pencil code
The core part of Assembly includes the pencil code, which is a language independent of the platform and CPU (platform-independent & CPU-independent ). During runtime, the pencil in the Assembly is compiled by JIT Compiler (just-in-time) into instructions for specific platforms and CPUs. With this mechanism,. Net assembly can run in a variety of different architectures, devices, and operating systems.

3. Type metadata)
Assembly metadata fully describes the Assembly inclusion type and reference type.

4. assembly manifest
assembly list is an important part of assembly, this list details each module in the Assembly, the version of the build assembly, all external Assembly referenced by the Assembly, and the pubic key token (if any) of the referenced assembly ).
extended topic:
q: how does Assembly use strong name to identify the referenced assembly?
A: we know that in an assembly (set as mainassembly), an assembly with a strong name (set as referencedassembly, assuming that the public key token is pkt1), the manifest of the mainassembly records the Public Key token of the referenced referencedassembly, that is, pkt1. When mainassembly is running, when CLR loads referencedassembly, CLR compares the Public Key token recorded in mainassembly manifest with the public key token of referencedassembly. If match is enabled, load it; otherwise, a filenotfound exception is thrown.


Assembly deployment methods Assembly deployment method
An assembly can be deployed via two methods alternatively
A) Private method private assembly
deploying the Assembly with the app in the same directory is called Private deployment. weak name Assembly can only be deployed via priviate deployment ..
All unpublished assemblies are called private assemblies. When the client references private assembly, a copy of assemly is created in the path of the client.
therefore, when releasing such applications, you only need to copy them with referenced assembly to a certain location on the machine, this deployment method is also called xcopy deployment .

B) Global method (shared assembly or public assembly)
Global deployment can deploy the assembly place where CLR can identify. as CLR search in the assemblies, it knows to find in such specific path. strong name assembly can be deployed via global deployment as welll as private deployment.
An assembly can be released in two ways: Private mode and global mode.

HOw to deploy strong name assemly via global deployment how to publish a strong signature Assembly through global deployment
A) deploy to where?
If an assembly will be access by more than one applications, then it shoshould be deployed via global deployment. it shoshould be deployed under a recognized directory by CLR, As long as app requires access specific assembly, the CLR can find it. this recognized direcoty is call GAC (Global Access cache: Global Assembly access cache) which is located on the Windows system path normally. such as c: \ windows \ Assembly \ GAC or c: \ winnt \ Assembly \ GAC
If an assembly is accessed by multiple programs, the Assembly must be published globally, and the shared Assembly must adopt a strong signature (strong name ). The Assembly must be published in a directory recognized by a CLR. When the program needs to access the assembly, the CLR must be able to find it. The directory recognized by the CLR is generally named GAC, which is generally located in the system directory, such as c: \ windows \ Assembly \ GAC.

B) GAC interior constructure GAC Internal Structure

Using comamd line, we can see that there are using directories, and related assebly file is stored in which. such as in Dir system. XML, there is a file called 1.0.5000.0 _ b73afaffa93dafa89 , This file is combined with the following parts:

(Version) _ (Culture) _ (publickeytoken)

So 1.0.5000.0 _ b73afaffa93dafa89 means

Version = 1.0.0.5

Culture = neutral,

Publickeytoken = b73afaffa93dafa89

If the culture is China, then it will be 1.0.5000 _ cn_b73afaffa93dafa89
In command line mode, we can see that there are many directories under GAC, each directory stores its corresponding Assembly file. The command of the Assembly file consists of several parts:
(Version) _ (Culture) _ (Public Key token)

C) how to deploy

The most frequently used tool is gacutil.exe to deploy strong name assembly.
How to sign an assembly using strong name, please refer to my another report:
Http://www.cnblogs.com/Winston/archive/2008/04/23/1026489.html
1) gacutil/I myassembly. dll Deploy myassembly. dll that has be signed with strong name.

2) gacutil/u myassembly. dll Uninstall myassembly.
The most common tool is gacutil, which is used to deploy an assembly.
Gacutil/I is used to deploy strong Assembly
Gacuitl/u is used to uninstall a strong assembly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.