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

CHAPTER 10 NAMESPACES AND ASSEMBLIES

Shared Assemblies and the GAC

Private assemblies are very useful, but sometimes you’ll want to put a DLL in a central place so that a single copy can be shared by other assemblies on the system. .NET has such a repository, called the global assembly cache (GAC). An assembly placed into the GAC is called a shared assembly.

Some important facts about the GAC are the following:

Only strongly named assemblies can be added to the GAC.

Although earlier versions of the GAC accepted only files with the .dll extension, you can now add assemblies with the .exe extension as well.

The GAC is located in a subdirectory named Assembly, of the Windows system directory.

Installing Assemblies into the GAC

When you attempt to install an assembly into the GAC, the security components of the CLR must first verify that the digital signature on the assembly is valid. If there is no digital signature or if it is invalid, the system will not install it into the GAC.

This is a one-time check, however. After an assembly is in the GAC, no further checks are required when it is referenced by a running program.

The gacutil.exe command-line utility allows you to add and delete assemblies from the GAC and list the assemblies it contains. The three most useful flags are the following:

/i: Inserts an assembly into the GAC

/u: Uninstalls an assembly from the GAC

/l: Lists the assemblies in the GAC

292

CHAPTER 10 NAMESPACES AND ASSEMBLIES

Side-by-Side Execution in the GAC

After an assembly is deployed to the GAC, it can be used by other assemblies in the system. Remember, however, that an assembly’s identity consists of all four parts of the fully qualified name. So, if the version number of a library changes or if it has a different public key, these differences specify different assemblies.

The result is that there can be many different assemblies in the GAC that have the same file name. Although they have the same file name, they are different assemblies and coexist perfectly fine together in the GAC. This makes it easy for different applications to use different versions of the same DLL at the same time, since they are different assemblies with different identities. This is called side- by-side execution.

Figure 10-18 illustrates four different DLLs in the GAC that all have the same file name— MyLibrary.dll. Looking at the figure, you can see that the first three come from the same company, because they have the same public key, and the fourth comes from a different source, since it has a different public key. These versions differ as follows:

An English version 1.0.0.0, from company A

An English version 2.0.0.0, from company A

A German version 1.0.0.0, from company A

An English version 1.0.0.0, from company B

Figure 10-18. Four different side-by-side DLLs in the GAC

293

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