Global Assembly Cache


The global assembly cache is, as the name implies, a cache for globally available assemblies. Most shared assemblies are installed inside this cache, but some private assemblies can also be found there. If a private assembly is compiled to native code using the native image generator, the compiled native code goes into this cache, too!

This section explores creating native images at installation time and viewing shared assemblies with the Global Assembly Cache Viewer and the Global Assembly Cache Utility.

Native Image Generator

With the native image generator Ngen.exe, you can compile the IL code to native code at installation time. This way the program can start faster because the compilation during runtime is no longer necessary. The ngen utility installs the native image in the native image cache. The physical directory of the native image cache is <windows>\assembly\NativeImages<RuntimeVersion>.

With ngen install myassembly, you can compile the MSIL code to native code and install it into the native image cache. This should be done from an installation program if you would like to put the assembly in the native image cache.

With ngen you can also display all assemblies from the native image cache with the option display. If you add an assembly name to the display option you get the information about all installed versions of this assembly and the assemblies that are dependent on the native assembly, as shown in Figure 15-27.

image from book
Figure 15-27

If the security of the system changes, it's not sure if the native image has the security requirements it needs for running the application. This is why the native images become invalid with a system configuration change. With the command ngen update all native images are rebuilt to include the new configurations.

Global Assembly Cache Viewer

The global assembly cache can be displayed using shfusion.dll, which is a Windows shell extension to view and manipulate the contents of the cache. A Windows shell extension is a COM DLL that integrates with the Windows explorer. You just have to start the explorer and go to the <windir>/assembly directory.

Figure 15-28 shows the Assembly Cache Viewer.

image from book
Figure 15-28

With the Assembly Cache Viewer, you can see the Global Assembly Name, Type, Version, Culture, and the Public Key Token. With the Type you can see if the assembly was installed using the native image generator. When you select an assembly using the context menu, it's possible to delete an assembly and to view the properties (see Figure 15-29).

image from book
Figure 15-29

You can see the real files and directories behind the assembly cache by checking the directory from the command line. Inside the <windir>\assembly directory there's a GAC and NativeImages_<runtime version> directory. GAC is the directory for shared assemblies, and in NativeImages_<runtime version> you can find the assemblies compiled to native code. If you go deeper in the directory structure you will find directory names that are similar to the assembly names, and below that a version directory and the assemblies themselves. This allows an installation of different versions of the same assembly.

Global Assembly Cache Utility (gacutil.exe)

The assembly viewer can be used to view and delete assemblies with the Windows explorer, but it's not possible to use it from scripting code that can be used from installation programs. gacutil.exe is a utility to install, uninstall, and list assemblies using the command line.

The following list explains some of the gacutil options:

  • gacutil /l lists all assemblies from the assembly cache

  • gacutil /i mydll installs the shared assembly mydll into the assembly cache

  • gacutil /u mydll uninstalls the assembly mydll




Professional C# 2005
Pro Visual C++ 2005 for C# Developers
ISBN: 1590596080
EAN: 2147483647
Year: 2005
Pages: 351
Authors: Dean C. Wills

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net