19.7 Creating a Shared Assembly

 <  Day Day Up  >  

You want to create a shared assembly.


Technique

To convert a private assembly into a shared assembly, you need to install it into the GAC. Note that the private assembly must already have a strong name .

You install an assembly into the GAC using another command-line tool, gacutil . The purpose of gacutil is quite simply to manage the placement and removal of assemblies in the GAC. To install an assembly into the cache, you should run gacutil with the -i flag. For example, to install an assembly, MyLibrary.dll , you use the following:

 
 gacutil i MyLibrary.dll 

Notice we assume the assembly in question is a DLL assembly. The whole point of getting an assembly in the GAC is so other applications can use its types. Almost invariably, the only assemblies you normally want to install as shared assemblies are DLL assemblies.

If an assembly has been delay-signed, you must mark it for verification skipping before attempting to install it in the GAC:

 
 sn Vr MyDelaySignedLibrary.dll gacutil I MyDelaySignedLibrary.dll 

Of course, once you re-sign a delay-signed assembly with sn -R , you can install it directly into the GAC, with no need for the additional sn “Vr step.

Comments

On occasions, you might want to uninstall an assembly from the GAC. To do that, you should run gacutil with the -u flag:

 
 gacutil u MyDelaySignedLibrary 

Note, however, there is a subtle difference in syntax between installing and uninstalling: When you install an assembly, you need to provide only the filename, because gacutil can read the full identity of the assembly from the file. Recall that the assembly identity includes the name, version, strong name, and culture of that assembly, and all this information is required to place the assembly in the cache. However, when you remove an assembly from the cache, you cannot specify a filename, so you need to specify instead the identity of the assembly. That's why the preceding code omitted the .dll extension from the name: We were specifying the assembly name, not the filename. Because this code indicates only the name of the assembly, the result is that all assemblies that have this name are removed from the GAC. If you know that there are multiple assemblies with a given name in the cache ”such as multiple versions of an assembly or copies of a satellite assembly with different cultures ”and you only want one of them removed, then you need to be more specific:

 
 gacutil u MyDelaySignedLibrary Version=3.1.0.0 

This line uninstalls any assemblies that have the name MyDelaySignedLibrary and the version number 3.1.0.0 , whereas the following line is even more specific:

 
 gacutil u MyDelaySignedLibrary Version=3.1.0.0 Culture=en-GB 

It uninstalls only the en-GB (that is, UK English) culture version of this assembly.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

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