2.8. The Global Assembly Cache

If you use an object from the .NET class library in your own code, you have to reference the assembly in which it is defined at compile time. For instance, if you want to use the MessageBox class in one of your applications, you need to make sure that the System.Windows.Forms assembly is made available to the compiler. This assembly contains the System.Windows.Forms namespace, which in turn contains the MessageBox class. The command-line statement needed to compile your source code is:

vbc /t:winexe /r:System.Windows.Forms.dll mycode.vb

Referencing one of your own assemblies is no different, but a full path to the assembly is expected. For example:

vbc /t:library /r:<path>\mylib.dll mycode.vb

A path is not necessary for System.Windows.Forms.dll because like all .NET class library assemblies, it lives in the global assembly cache (GAC). The GAC is a directory, shown in Figure 2-5, that contains assemblies that are meant to be shared by several applications on a single machine. The actual path to the GAC is <%windir%>/assembly.

Figure 2-5. The GAC in an Explorer list pane

2.8.1. Strong Names

If you want to share an assembly by putting it in the GAC, it must have a strong name. A strong name defines the assembly's identity: its name, version number, and culture information (if it exists), a public key, and a digital signature.

2.8.1.1. Strong ...

Get Object-Oriented Programming with Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.