March 31, 2010

Creating New Custom Actions! Some tips to define Custom Error Messages...

Windows Installer has a long list of predefined error messages and there are many scenarios in which we would need to define Custom error messages for Custom Actions.

Windows Installer suggests the following Tips while creating Custom Error Messages.

  • The error number must be a non-negative integer.
  • The range from 25000 to 30000 is reserved for errors from custom actions. Authors of custom actions may use this range for their custom actions.
However InstallShield users have to be extra carefull to exclude the error codes ranging from 27500 to 27554, which is already being used by recent versions of InstallShield (verified in IS 12, 2009 & 2010) for IIS, Database, COM+, XML etc., related functionality.

March 10, 2010

How to register a .Net assembly into GAC using VBScript CA?

This article focuses on registering .Net assembly into GAC using VBScript Custom Action. We generally use the two approaches detailed here to register .Net Assembly into GAC. In case, if both the approach does not seem to work for your .Net DLL and you observe the following, then VBScript CA detailed below can be used to register the assembly.
  • When building the InstallShield project with .Net COM Interop property set to 'YES' (along with Destination Path to [GlobalAssemblyCache]), if you get the error =>
    Error -6210: An error occurred building COM .NET Interop information for Component [1].
    [1] indicates the part of your installation that is causing this error.
  • When .Net COM Interop property is set to 'NO', building the InstallShield project would succeed but running the installation does not register the .Net assembly into GAC.
Steps to Register .Net Assembly into GAC:
• Add the .Net Assembly to be registered under Support directory.
• Add a VBScript Custom Action (stored in binary table - MSI Type Number : 3078)– RegisterAsmToGAC with the below mentioned code snippet.

Function RegisterAsmToGAC
on error resume next
' Declaration
Const IDABORT=3
Dim szCommand, szCommand1, szCommand2, szCommand3
Dim PropArray, szSupportDir, sProductName,sAssemblyName
' Reading & Parsing the property values in Deferred CA
PropArray = Split(Session.Property("CustomActionData"), ";")
szSupportDir = PropArray(0)
sProductName = PropArray(1)
sAssemblyName = PropArray(2)
'Display Debug Message
'MsgBox szSupportDir, ,sProductName


' Using GACInstaller.exe utility downladed from http://www.codeproject.com/KB/install/GAC_Installer.aspx
szCommand1 = Chr(34) & szSupportDir & "\GacInstaller.exe" & Chr(34)
szCommand2 = " i "
szCommand3 = Chr(34) & szSupportDir & sAssemblyName & Chr(34)
szCommand = szCommand1 & szCommand2 & szCommand3
'MsgBox szCommand, ,sProductName
Set wshShell = WScript.CreateObject ("WScript.Shell")
rc = wshshell.Run(szCommand, 0, True)
if rc <> 0 then
       MsgBox "Error Registering the Assembly", ,sProductName
       wscript.quit
end if

if Err.Number <> 0 then
       MsgBox Err.Number & " - " & Err.Description, ,sProductName
       RegisterAssemblyGAC = IDABORT
End If
End Function

• The RegisterAsmToGAC CA uses 3 MSI Properties (say SUPPORTDIR, ProductName and .Net Assembly to be  registered). By default the MSI properties will not be available to the Custom actions that are in Defered mode.
• To pass parameter to Deferred CA, create a Set Property CA (MSI Type Number: 51) as 'SetRegisterAsmToGAC', set the property name as RegisterAsmToGAC and set the semicolon separated property names to the property value as [SUPPORTDIR];[ProductName];[AssemblyNameToBeRegistered].
• Schedule the SetRegisterAsmToGAC as a Immediate CA after RegisterProduct.
• Schedule the RegisterAssemblyGAC as a Deferred in System Context after SetRegisterAsmToGAC.