February 25, 2010

How to Register a .Net assembly into GAC using WiX?

Ealier we have seen some articles to register a .Net assembly into GAC using either gacutil.exe or RegAsm.exe. In this article we will see the code snippet to register the assembly into GAC using WiX.

<Directory Id="ProgramFilesFolder">
<Directory Id="ProductDirectory" Name="$(var.ProductName)">
      <Directory Id="GAC" Name="GAC">
          <Component Id="MyGACControl" Guid="55857611-A13E-51ED-897B-A78830F68ADC" DiskId="1">
                <!-- Registering assembly in GAC -->
               <File Id="F_MyGACControl" Name="MyGACCtrl.dll" LongName="MyGACControl.dll" Source="$(var.SrcPath)

               \MyGACControl.dll" KeyPath="yes" Assembly=".net"/>
           </Component>
      </Directory>
</Directory>
</Directory>

The highlighted text - Name="GAC" Assembly=".Net", in the above code drives the .Net assembly registration into GAC.


Read the following related articles:
  1. How to register a .Net assembly into GAC in a development environment?
  2. How to Register .Net assembly into GAC using InstallShield 2010?

February 16, 2010

How do you check whether the Patch is Installed already?

This article details on the approach to detect whether the patch is applied or not and prompt the user accordingly. This post applies to Basic MSI & InstallScript MSI Projects and is tested in InstallShield 2008, 2009 & 2010 with SP1. Refer here for the steps to create a Patch using InstallShiled.

• Add a VBScript Custom Action (stored in binary table)– CheckIfPatchInstalled
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Function: CheckIfPatchInstalled
''' Purpose: Checks to see if a patch is installed and sets the value of the property
''' 'PATCHINSTALLED' to "true". This property value is used by the Custom action
''' 'CheckIfPatchInstalledError' to display an error.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function IsPatchInstalled()
            
Dim sProductCode, sProductVersionHF, sProductVersionCurrent
             

             On Error Resume Next
              sProductCode = Session.Property("ProductCode")
             
sProductVersionCurrent = Session.Installer.ProductInfo(sProductCode, "VersionString")
             
sProductVersionBase = Session.Property("ProductVersion")
             
If (sProductVersionCurrent = sProductVersionBase) Then
              
     Session.Property("PATCHINSTALLED") = "true"
             
End If

End Function

• Schedule the CheckIfPatchInstalled as Immediate CA after ISSetupFilesExtract in both Install UI Sequence and Install Exec Sequence with the condition PATCH.
• Add a property PATCHINSTALLED in property manager and leave it empty.
• Add an Error Custom Action as Immediate CA after CheckIfPatchInstalled in both Install UI Sequence and Install Exec Sequence with the condition PATCH AND PATCHINSTALLED.
• Add the appropriate error message say "An existing upgrade is already installed. Please remove it before installing this upgrade." for the Error CA Or Add an entry (Error Number & Message) to the Error Table in the direct editor and use the Error Number in the CA

Create the Patch and apply the patch where the main installer is installed. Running the patch again on the same machine should display the message "An existing upgrade is already installed. Please remove it before installing this upgrade." abort the installation.