Innovative Application Packaging Cloud

Innovative Application Packaging Cloud
Automated Packaging Self-Service (APS) is an innovative cloud solution that provides smart application packaging, testing and documentation.

Monday, October 17, 2011

Basics of Assemblies, GAC (Global Assembly Cache) and How to install Assemblies in GAC through a windows installer package


Versioning Problems

Currently two versioning problems occur with Win32 applications:
      • Versioning rules cannot be expressed between pieces of an application and enforced by the operating system. The current approach relies on backward compatibility, which is often difficult to guarantee.
      • There is no way to maintain consistency between sets of components that are built together and the set that is present at run time.
These two versioning problems combine to create DLL conflicts, where installing one application can inadvertently break an existing application because a certain software component or DLL was installed that was not fully backward compatible with a previous version. Once this situation occurs, there is no support in the system for diagnosing and fixing the problem.

Solutions for Versioning Problems:
      •  Isolation(Refer my Previous Post to get detail about isolation concept at my blog)
      • Windows 2000 locks files that are shipped with the operating system in the System32 directory so they cannot be inadvertently replaced when applications are installed.
Assembly as a solution for Versioning Problems

To solve versioning problems, as well as the remaining problems that lead to DLL conflicts, the runtime uses assemblies to do the following:
  • Provide the infrastructure to allow multiple versions of a component to be run simultaneously (called side-by-side execution).
  • Provide the infrastructure to enforce versioning rules
  •  Enable developers to specify version rules between different software components.

Assemblies Overview
  •  An Assembly is a partially compiled code library for use in deployment, versioning and security. An Assembly can consist of one or more code files.
  •     It contains code that the common language runtime executes. Microsoft intermediate language (MSIL) code in a portable executable (PE) file will not be executed if it does not have an associated assembly manifest.

There are two types of Assemblies:
  1.  Process assemblies (EXE)
  2. Library assemblies (DLL)
Assembly names
The name of an assembly consist of four parts:
  •  The Short Name
  • The culture
  • The version
  • A public key token
Installer Tables and Assemblies

Although you can install assemblies—both executables and DLLs—like normal files, most installation building tools recognize that they're assemblies, not just traditional code files. These tools therefore populate two Windows Installer database  tables that are specific to assemblies, MsiAssembly and MsiAssemblyName.for complete information on this table please refer Microsoft MSI SDK.

Benefits of Assembly
  • Assemblies are designed to simplify application deployment and to solve versioning problems that can occur with component-based applications.
  • Assembly simplify uninstalling and replicating
  • Assembly supports side-by-side execution
Assembly manifest

            Every assembly, whether static or dynamic, contains a collection of data that describes how the elements in the assembly relate to each other. The assembly manifest contains this assembly metadata. An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes. The assembly manifest can be stored in either a PE file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a standalone PE file that contains only assembly manifest information. 


What is Global Assembly Cache?

  • Each computer on which the common language runtime is installed has a machine-wide code cache called the 'Global Assembly Cache'. The global assembly cache (or GAC as it is commonly known) stores assemblies specifically designated to be shared by several applications on the computer. The global assembly cache is located in 'Windows/WinNT' directory and inherits the directory's access control list that administrators have used to protect the folder.
  • Assemblies placed in the GAC must have the same assembly name as file name (not including the file name extension). For example, an assembly with the assembly name of 'myAssembly' must have a file name of either 'myAssembly.exe' or 'myAssembly.dll'. 
Scenarios for installing Assemblies in GAC

There are multiple reasons why an assembly should be installed in GAC:
  • File Security
  • Shared Loaction
  • Side-by-Side Versioning
  • As an Additional Search Location

How to Install Assemblies in GAC?

A utility called GACUtil.exe can be used to install Assemblies into GAC. Certain command line options are present for using this utility for installation of Assemblies into GAC.
Command line option for installation of Assembly is:
<Complete Path to GACutil.exe> /i <Complete Path to the file> /silent
This Command line would create an assembly with the same name as the filename (not including the file name extension)
Command line option for uninstallation of Assembly is:
<Complete Path to GACUtil.exe> /u <Name of the Assembly>

How to Install and uninstall assemblies in GAC via a Windows Installer Package?

Include the file GACUtil.exe in the package. Then following two approaches can be used to install the assemblies in GAC.        
  1. Through Custom Action "Execute Program from Installed Files"(I will cover this approach here in my blog)
  2.  Through Custom action "Call VBScript from Installation"
Through Custom Action “Execute Program from Installed Files”
   Install Assemblies
·        “Select Execute Program from installed files” custom action from MSI Script Tab. Following dialog box would appear.
·         Select Details Tab from this dialog box and fill the details.
·        In Command line Arguments Textbox, fill the details as
/i "[INSTALLDIR]Bw\SAP.Connector.dll" /silent, This will silently install the assembly ‘SAP.Connector’ for the file ‘SAP.Connector.dll’


·        Select Location Tab and place this custom Action in “Normal Execute Immediate/Deferred” sequence before InstallFinalize



·        Select the Properties Tab and fill the details as shown below.

Uninstall Assemblies
·        “Select Execute Program from installed files” custom action from MSI Script Tab. Following dialog box would appear.
·        Select Details Tab from this dialog box and fill the details.
·        In Command line Arguments Textbox, fill the details as
/u SAP.Connector /silent, This will silently uninstall the assembly ‘SAP.Connector’ for the file ‘SAP.Connector.dll’


·        Select Location Tab and place this custom Action in “Normal Execute Immediate/Deferred” sequence after InstallIntialize.


·        Select the Properties Tab and fill the details as shown below.




Note: Most of the tools will populate the Assembly tables in the MSI for you, the utilities such as gacutil.exe and custom action usage are for understanding.

No comments: