2.8 The Global Assembly Cache

only for RuBoard

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. Strong Name utility

The first step toward giving an assembly a strong name is creating a key pair file that contains the public/private keys used to sign the assembly. To create the key pair file, use the Strong Name tool from the command line:

 sn -k hello.snk 

Doing so creates a key pair file named hello.snk . Assembly Linker

Next, you need to use the Assembly Linker (AL) to sign the assembly with the key pair file. This utility is not specific to any language, so you can't feed it source code. You do need to compile your library to a module first, using a command line like the following:

 vbc /t:module hello.vb 

Compiling your library produces a module called hello.netmodule . Now you can use AL to create a signed assembly like this:

 al /out:hello.dll hello.netmodule /keyfile:hello.snk 

The result is a signed assembly with the name hello.dll . Gacutil

Now that you have a signed assembly, you can use the Global Assembly Cache tool, gacutil.exe , to install it to the GAC, as shown in the following command:

 gacutil /i hello.dll 
only for RuBoard

Object-Oriented Programming with Visual Basic. Net
Object-Oriented Programming with Visual Basic .NET
ISBN: 0596001460
EAN: 2147483647
Year: 2001
Pages: 112
Authors: J.P. Hamilton
Similar book on Amazon

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