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.