Shared Assembly Deployment

for RuBoard

The Assembly Cache is a known 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 alongside one another. The global assembly cache contains shared assemblies that are globally accessible to all .NET applications on the machine. A download assembly cache 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 global assembly cache, you must digitally sign the assembly as discussed earlier. Developers can place the assembly into the global assembly cache by using either using 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 a 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 

Note that the -i option is case sensitive. You should then see the console message "Assembly successfully added to the cache." The effect of this command is that a new global assembly cache node named Customer is created in the \WINNT\Assembly directory. As can be seen in Figure 7-6, the version number and originator (i.e., public key token) are displayed for the assembly in Windows Explorer. We changed the version of the component to 1.0.0.0 to distinguish it from the unsigned version.

Figure 7-6. Windows Explorer showing the global assembly cache.

graphics/07fig06.gif

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 . [8] 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 7-7 shows the top-level window of this tool. To use the tool to add an assembly to the GAC, 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.

[8] 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 7-7. .NET Admin Tool supports many .NET administrative functions.

graphics/07fig07.gif

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 signed with a different key. The default binding policy for shared assemblies is an exact 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? Place a Customer assembly with the version 1.1.0.0 in the GAC. Figure 7-8 displays both versions of the Customer assembly installed in the Global Assembly Cache with their respective version numbers and identical public key tokens.

Figure 7-8. .NET Admin Tool with side-by-side components in the global assembly cache.

graphics/07fig08.gif

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.

for RuBoard


Application Development Using C# and .NET
Application Development Using C# and .NET
ISBN: 013093383X
EAN: 2147483647
Year: 2001
Pages: 158

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