Shared Assembly Deployment

Team-Fly    

 
Application Development Using Visual Basic and .NET
By Robert J. Oberg, Peter Thorsteinson, Dana L. Wyatt
Table of Contents
Chapter 9.  Assemblies and Deployment


The Assembly Cache is a directory where the CLR looks for shared, side-by-side assemblies. The term "side-by-side" means that multiple versions of the same component may reside within the assembly cache along side one another. The GAC contains shared assemblies that are globally accessible to all .NET applications on the machine. There is also a download assembly cache that is accessible to applications such as Internet Explorer that automatically download assemblies over the network.

Deploying a Shared Assembly

Before an assembly can be deployed into the GAC, you must first digitally sign the assembly as discussed in a previous section. Developers can then place the assembly into the GAC by using either the Global Assembly Cache Utility Gacutil.exe command-line utility, the Windows Explorer with the assembly cache viewer Windows shell extension, or the .NET Admin Tool. Deploying shared assemblies on an end user 's machine should be done with an installation program.

To illustrate this process, we will deploy in the GAC the version of our Customer and Hotel assemblies that are in the SignedCaseStudy directory. To deploy the components into the GAC, you can use the command-line utility Gacutil.exe .

 Gacutil -i Customer.dll 

You should then see the console message Assembly successfully added to the cache. The effect of this command is that a new GAC node named Customer is created in the \WINNT\Assembly directory. As can be seen in Figure 9-15, the version number and originator (i.e., public key token) are displayed for the assembly in Windows Explorer.

Figure 9-15. Windows Explorer showing the Global Assembly Cache.

graphics/09fig15.jpg

You can also can drag and drop a component into the Assembly directory to install it in the GAC. Alternatively, you can use the .NET Admin Tool to install an assembly into the GAC. The .NET Admin Tool is an MMC snap-in located at \ WINNT\Microsoft.NET \Framework\v1.0.2914\ mscorcfg .msc . [5] The directory version number will be different in a later release of the .NET Framework. While it may seem overkill to introduce a third tool, this MMC snap-in is a very useful utility that simplifies many tasks . Figure 9-16 shows the top-level window of this tool. To add an assembly to the GAC using this tool, just select Assembly Cache in the left pane, right-mouse-click, and select Add. Using the dialog box that pops up to navigate to the file, select the assembly you want to add, and click the Open button.

[5] To run a snap-in, you can just double-click on the .msc file in Windows Explorer. Since we are going to use the .NET Admin Tool extensively, you may wish to add the tool to the Visual Studio Tools menu, which you can do through Tools External Tools... For the command enter mmc.exe , and for the argument, enter the complete path to mscorcfg.msc .

Figure 9-16. .NET Admin Tool supports many .NET administrative functions.

graphics/09fig16.jpg

After you have installed the assemblies in the GAC, copy just the AcmeGui client program in the SignedCaseStudy directory to another directory. You can now run it without any assemblies in the same directory.

What happens if we remove the version of Customer we installed in the GAC and place in the GAC a Customer assembly signed with the same key, but a different version? A FileNotfoundException is thrown by the CLR. We would get the same result if we replaced it with a Customer assembly that had the same version, but was signed with a different key. The default binding policy for shared assemblies is an exact and full name match.

Versioning Shared Components

What happens if you install two versions of the same assembly in the GAC that were signed with the same key? You can place two Customer assemblies with different version numbers in the GAC. Figure 9-17 displays two versions of the Customer assembly installed in the GAC with their distinct version numbers and identical public key tokens.

Figure 9-17. .NET Admin Tool with side-by-side components in the Global Assembly Cache.

graphics/09fig17.jpg

This is called by-side deployment. Both assemblies are available to client programs that require them. Programs can bind to either of them without fear of getting the wrong version.


Team-Fly    
Top
 


Application Development Using Visual BasicR and .NET
Application Development Using Visual BasicR and .NET
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 190

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