Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Daniel Solis - Illustrated C# 2010 - 2010.pdf
Скачиваний:
16
Добавлен:
11.06.2015
Размер:
11.23 Mб
Скачать

CHAPTER 10 NAMESPACES AND ASSEMBLIES

The Structure of an Assembly

As you saw in Chapter 1, an assembly does not contain native machine code, but Common Intermediate Language (CIL) code. It also contains everything needed by the Just-in-Time (JIT) compiler to convert the CIL into native code at run time, including references to other assemblies it references. The file extension for an assembly is generally .exe or .dll.

Most assemblies are composed of a single file. Figure 10-13 illustrates the four main sections of an assembly.

The assembly manifest contains the following:

The identity of the assembly

A list of the files that make up the assembly

A map of where things are in the assembly

Information about other assemblies that are referenced

The type metadata section contains the information about all the types defined in the assembly. This information contains everything there is to know about each type.

The CIL section contains all the intermediate code for the assembly.

The resources section is optional but can contain graphics or language resources.

Figure 10-13. The structure of a single-file assembly

285

CHAPTER 10 NAMESPACES AND ASSEMBLIES

Although most assemblies comprise a single file, some have more. For an assembly with multiple modules, one file is the primary module, and the others are secondary modules.

The primary module contains the manifest of the assembly and references to the secondary modules.

The file names of secondary modules end with the extension .netmodule.

Multiple-file assemblies are considered a single unit. They are deployed together and versioned together.

Figure 10-14 illustrates a multifile assembly with secondary modules.

Figure 10-14. A multifile assembly

286

CHAPTER 10 NAMESPACES AND ASSEMBLIES

The Identity of an Assembly

In the .NET Framework, the file names of assemblies are not as important as in other operating systems and environments. What is much more important is the identity of an assembly.

The identity of an assembly has four components that together should uniquely identify it. These four components are the following:

Simple name: This is just the file name without the file extension. Every assembly has a simple name. It is also called the assembly name or the friendly name.

Version number: This consists of a string of four period-separated integers, in the form

MajorVersion.MinorVersion.Build.Revision—for example, 2.0.35.9.

Culture information: This is a string that consists of two to five characters representing a language, or a language and a country or region. For example, the culture name for English as used in the United States is en-US. For German as used in Germany, it is de-DE.

Public key: This 128-byte string should be unique to the company producing the assembly.

The public key is part of a public/private key pair, which is a set of two very large, specially chosen numbers that can be used to create secure digital signatures. The public key, as its name implies, can be made public. The private key must be guarded by the owner. The public key is part of the assembly’s identity. We will look at the use of the private key later in the chapter.

287

CHAPTER 10 NAMESPACES AND ASSEMBLIES

The components of an assembly’s name are embedded in the assembly’s manifest. Figure 10-15 illustrates this section of the manifest.

Figure 10-15. The components of an assembly identity in the manifest

Figure 10-16 shows some of the terms used in the .NET documentation and literature regarding the identity of an assembly.

Figure 10-16. Terms for an assembly’s identity

288

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]