Section 19.3. Global Deployment

19.3. Global Deployment

In the previous section, we stated that most applications are deployed by copying files to the proper directory. The exception occurs when you wish to use the same assembly in more than one application. In this case, you use global deployment .

There are many scenarios in which you might want to have a common assembly file accessible to multiple applications. A firm might have two different web sites on a server, both providing access to the same database. One web site is free of charge and open to the public but of limited functionality, but the other is fully functional, requiring a paid subscription. Since both sites access the same database, they will have common database query routines. They might also have common login routines. Using the same assembly to contain those common routines will enhance maintainability. Another scenario might be a web-hosting firm that has many web sites running on a server. It might want to offer some functionality to all its client web sites. Encapsulating this functionality in a globally available assembly would make this easy to offer and maintain.

Another consideration is versioning. When assemblies are local to an application, then each application can have its own version of common assemblies. The .NET Framework allows for global assemblies to have multiple versions. Each application making use of the global assembly can either specify the version it wants to use or take the latest version. By specifying the version, an application will not break if a newer version of the assembly introduces signature changes or bugs .

To provide global availability of an assembly, it must be installed to the GAC. The GAC is a machine-wide location for code to be shared among multiple applications on that machine. Typically, it is physically located at c:\ windows \assembly . However, you cannot just copy an assembly file to that directory and have it be made available to all the applications. The assembly needs to be registered with the GAC, using the .NET command-line utility GacUtil.exe .

To make an assembly file suitable for inclusion in the GAC, it must have assembly information compiled into it. This is done using Assembly attributes . These Assembly attributes can either be included in the same source code file as the class or classes being compiled into the assembly or can be in a separate source code file that is compiled into the assembly along with the class source code file(s). The format of the Assembly attributes look like this:

 [Assembly:attributeName(attributeValue)] 

attributeName is the name of the Assembly attribute, and attributeValue is the string value assigned to the attribute. So, for example, if you're assigning the AssemblyVer-sionAttribute , it would look like the following:

 [Assembly: AssemblyVersionAttribute ("1.0.3.101")] 

Table 19-3 lists the available Assembly attributes with a brief description.

Table 19-3. Assembly attributes

Attribute

Description

AssemblyCompanyAttribute

String containing company name.

AssemblyConfigurationAttribute

String configuration, such as Retail or Debug. Not used by CLR.

AssemblyCopyrightAttribute

String containing copyright information.

AssemblyCultureAttribute

Field indicating culture supported by the assembly.

AssemblyDefaultAliasAttribute

String containing default alias for the assembly. Can contain a friendly name.

AssemblyDelaySignAttribute

Boolean indicating delayed application of digital signature.

AssemblyDescriptionAttribute

String containing short description of the assembly.

AssemblyFileVersionAttribute

String containing Win32 file version number. Defaults to assembly version.

AssemblyFlagsAttribute

Flag indicating the kind of side-by-side execution allowed.

AssemblyInformationalVersionAttribute

String containing version information not used by the CLR.

AssemblyKeyFileAttribute

String containing name of file with either public key signature if using delayed signing, or both public and private keys. Filename is relative to output file path and not source file path .

AssemblyKeyNameAttribute

String containing key container.

AssemblyName

String containing an assembly's unique name.

AssemblyProductAttribute

String containing product information.

AssemblyTitleAttribute

String containing friendly name for the assembly.

AssemblyTrademarkAttribute

String containing trademark information.

AssemblyVersionAttribute

A numeric version representation, in the form major . minor . build.revision .


If you are using Assembly attributes in a source file, you must reference the System.Reflection namespace with the using keyword in C#.

For an assembly to be included in the GAC, it must have a strong name .

Once all this is in place, you can use GacUtil.exe to add the assembly to the GAC. The syntax is:

 gacutil /i pathToDLL\myDLL.DLL 

where pathToDLL is the path to the directory containing the assembly file, and myDLL.DLL is the name of the assembly file.

The GacUtil.exe utility has several command-line switches. For a complete list, enter the following at a command prompt:

 gacutil /? 

Some of the more commonly used switches are described in Table 19-4.

Table 19-4. Some common switches to GacUtil.exe

Switch

Description

/i

Installs an assembly to the GAC.

/u

Uninstalls an assembly from the GAC. If the name of the assembly to be uninstalled has no qualifying information, such as version, then all assemblies of that name will be uninstalled .

/l

Lists all the assemblies installed in the GAC.


To use a global assembly in applications, it must be registered in the machine.config file or the machine level web.config file. To add the above assembly to the configuration file, add the following line to the <configuration><system.web><compilation><assemblies> section:

 <add assembly="myDLL, Version=1.0.3.101, Culture=neutral,        PublicKeyToken=   nnnnnnnn   "/ > 

where nnnnnnnn is obtained from GacUtil by running:

 gacutil /l 

from the command line, finding myDLL in the listing, and copying the public key token into place.



Programming ASP. NET
Programming ASP.NET 3.5
ISBN: 0596529562
EAN: 2147483647
Year: 2003
Pages: 173

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