Some rough notes on the Global Assembly Cache (GAC)

The GAC is essentially visible as a special folder, normally residing at C:\Windows\Assembly. It can only contain assemblies, and these assemblies must be strongly named. The assemblies within the gac are essentially dlls that can be used by all applications on the computer – note that the various .net assemblies appear in the gac – e.g. system.text.

Note that assemblies dragged and drop into the gac folder are only referenced by the gac, the actual assemblies still reside in their original location. To actually copy an assembly to the gac, you must use gacutil.

A strong named assembly is one that has been signed via a public key (part of a keypair). A keypair can be generated with the strongly naming tool (that comes with visual studio / .net). Note that you can assign an assembly when built (providing you have a keypair) – by specifying certain attributes in the projects assemblyinfo.cs file. Once an assembly has been strongly named, you can simply copy it to the gac location – it will then be available to all applications.

[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("C:\path\to\publickey")]
[assembly: AssemblyKeyName("The.Key.Name")]

Note that delay sign means that the assembly can be signed later (if say only an administrator, not a developer has access to the relevant private key / certificate.

Also note that if you just strongnaming an assembly, you don’t need to distribute a public key or similar.

Also note that assemblies in the gac cannot be reference in visual studio (or at least easily – without editing registry keys etc). Instead, you must reference a copy of the relevant dll locally (so the dll should exist locally). Note that once the relevant project using that reference is build, you no longer need the dll locally if it resides in the gac. This is because assemblies are searched by fusion.dll runs (which controls the gac). This looks in the gac for an assembly before it looks locally.

Some links…

Note that these notes are very rough atm, i will hopefully tidy them up and add more info at some point.

You May Also Like

About the Author: rnowik

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.