Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






Nbsp;   The Global Assembly Cache

Now that you know how to create a strongly named assembly, it’s time to learn how to deploy this assembly and how the CLR uses the information to locate and load the assembly.

If an assembly is to be accessed by multiple applications, the assembly must be placed into a well- known directory, and the CLR must know to look in this directory automatically when a reference to the assembly is detected. This well-known location is called the global assembly cache (GAC). The exact location of the GAC is an implementation detail that is subject to change with different versions of the .NET Framework. However, you can typically find it in the following directory:

%SystemRoot%\Microsoft.NET\Assembly

 

The GAC directory is structured. It contains many subdirectories, and an algorithm is used to gen- erate the names of these subdirectories. You should never manually copy assembly files into the GAC; instead, you should use tools to accomplish this task. These tools know the GAC’s internal structure and how to generate the proper subdirectory names.

While developing and testing, you can use the most common tool for installing a strongly named assembly into the GAC, which is GACUtil.exe. Running this tool without any command-line arguments yields the following usage.

 

Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

 

Usage: Gacutil <command> [ <options> ] Commands:

/i <assembly_path> [ /r <...> ] [ /f ]

Installs an assembly to the global assembly cache.

 

/il <assembly_path_list_file> [ /r <...> ] [ /f ]

Installs one or more assemblies to the global assembly cache.


/u <assembly_display_name> [ /r <...> ]

Uninstalls an assembly from the global assembly cache.

 

/ul <assembly_display_name_list_file> [ /r <...> ]

Uninstalls one or more assemblies from the global assembly cache.

 

/l [ <assembly_name> ]

List the global assembly cache filtered by <assembly_name>

 

/lr [ <assembly_name> ]

List the global assembly cache with all traced references.

 

/cdl

Deletes the contents of the download cache

 

/ldl

Lists the contents of the download cache

 

/?

Displays a detailed help screen

 

Options:

/r <reference_scheme> <reference_id> <description>

Specifies a traced reference to install (/i, /il) or uninstall (/u, /ul).

 

/f

Forces reinstall of an assembly.

 

/nologo

Suppresses display of the logo banner

 

/silent

Suppresses display of all output

 

As you can see, you can invoke GACUtil.exe, specifying the /i switch to install an assembly into the GAC, and you can use GACUtil.exe’s /u switch to uninstall an assembly from the GAC. Note that you can’t ever place a weakly named assembly into the GAC. If you pass the file name of a weakly named assembly to GACUtil.exe, it displays the following error message: Failure adding assembly to the cache: Attempt to install an assembly without a strong name.



       
   
 

 

Using GACUtil.exe’s /i switch is very convenient for developer testing. However, if you use GACUtil.exe to deploy an assembly in a production environment, it’s recommended that you use GACUtil.exe’s /r switch in addition to specifying the /i or /u switch to install or uninstall the assem- bly. The /r switch integrates the assembly with the Windows install and uninstall engine. Basically,

it tells the system which application requires the assembly and then ties the application and the assembly together.


 

The GACUtil.exe tool doesn’t ship with the end-user .NET Framework redistributable package. If your application includes some assemblies that you want deployed into the GAC, you should use the Windows Installer (MSI), because MSI is the only tool that is guaranteed to be on end-user machines and capable of installing assemblies into the GAC.

       
   
 
 

 

What is the purpose of “registering” an assembly in the GAC? Well, say two companies each pro- duce an OurLibrary assembly consisting of one file: OurLibrary.dll. Obviously, both of these files can’t go in the same directory because the last one installed would overwrite the first one, surely breaking some application. When you install an assembly into the GAC, dedicated subdirectories are created under the %SystemRoot%\Microsoft.NET\Assembly directory, and the assembly files are copied into one of these subdirectories.

Normally, no one examines the GAC’s subdirectories, so the structure of the GAC shouldn’t really matter to you. As long as the tools and the CLR know the structure, all is good.

 


Date: 2016-03-03; view: 707


<== previous page | next page ==>
Nbsp;   Giving an Assembly a Strong Name | Nbsp;   Building an Assembly That References a Strongly Named Assembly
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.008 sec.)