Intel® Software Network Knowledge Base Wiki


Constructing Nav Tree
One Moment...

(refresh menu)



 
Welcome, Guest | Quick Login | Register

.NET


How to Make a .NET Assembly Globally Accessible

Version 4, Changed by KYLEX.S.LEWIS@INTEL.COM on 1/2/2008
Created by: KYLEX.S.LEWIS@INTEL.COM

Challenge

Share a .NET assembly among multiple applications. The CakeInfo assembly created in the item "How to Use a .NET Assembly" is an example of a private assembly:

            using System;
            using CakeUtils;
            namespace SizeCake
            {
               public class SizeTest
               {
                  public static void Main(string [] args)
                  {
                     short numEaters;
                     numEaters = CakeInfo.FeedsHowMany(10, CakeShape.Hexagonal,
                     CakeFilling.Sponge);
                     Console.WriteLine("This cake will feed " + numEaters +" people.");
                     }
                  }
            }

 

A private assembly is used exclusively by a single application, and it typically resides in the same folder as the application. If the assembly is updated and recompiled, the new version overwrites the old.

Solution

Make the assembly globally accessible and place it in the Global Assembly Cache (GAC). The GAC also allows multiple versions of the same assembly to coexist.

Before an assembly can be placed in the GAC, it must be given a strong name. A strong name guarantees uniqueness and includes the filename, version information, culture information, and a digital signature generated using a public/private key pair. The developer can manually specify the filename, version, and culture details, and he or she can generate a public/private key pair using the sn utility supplied with the .NET Framework SDK:

            sn -k CakeUtilsKey.snk

 

The -k option causes the keys generated to be written to the specified file (CakeUtilsKey.snk). The CakeInfo library indicates that a digital signature should be generated using these keys by specifying the AssemblyKeyFile attribute.

            using System.Reflection;
            [assembly: AssemblyVersion("2.0.*")]
            [assembly: AssemblyKeyFile("CakeUtilsKey.snk")]
            namespace CakeUtils
            {
            ...
            }
 

 

After rebuilding the assembly, the resultant DLL can be deployed to the GAC using the gacutil command:

            gacutil /i CakeInfo.dll

 

The /i parameter indicates that the assembly should be installed into the GAC. Other options are available for removing assemblies from the GAC, and listing the contents of the GAC. Applications can link to assemblies in the GAC using the /r parameter to the csc command.

This item is part of a larger body of items that contrast the ways in which versioning and dynamic linking are handled by Windows* and the .NET Common Language Runtime* (CLR), as opposed to by UNIX-based operating systems such as Linux* or Solaris.*

Source

Versioning, Libraries, and Assemblies

 



Served
25 Knowledge Bases
604 Pages
Search
Powering Up Search...


Vote on this Page

Tags For This Page
Loading Tags..

Tag This



Additional legal information