RegAsm & DLL Installation - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

JaedenRuiner
Posts: 12
Joined: Thu Apr 01, 2010 4:12 am

RegAsm & DLL Installation

Hello,
I apologize that this isn't a "Problem", its a question, but there seemed no other place I could ask. When using Advanced Installer to "register a .Net Assembly for COM" the system automatically adds the HKCR entries for the different classes that are interpreted by the RegAsm tool. However, I am working to install a .Net Assembly for COM, but part of the assembly itself runs some custom entries upon the calling of RegAsm /codebase mydll.dll.

The Assembly is a File Generator for Visual Studio Extensibility, so It has to insert some entries into the Visual Studio Registry Key, to add it to the supported Visual Studio COM File Generators. Now, when i run RegAsm/codebase mydll.dll, this takes place automatically. With Advanced Installer grabbing the "default" registry entries from my dll, through the regasm tool, does it still run regasm on the dll on installation, or do I have to do something else to get my custom entries for Visual Studio to install?

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: RegAsm & DLL Installation

Hi,

The codebase option is used automatically for assemblies which support it. Therefore, registering an assembly for COM Interoperability should have the same effect as "regasm /codebase".

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
JaedenRuiner
Posts: 12
Joined: Thu Apr 01, 2010 4:12 am

Re: RegAsm & DLL Installation

Well,

I am aware of that when using regasm manually from the command line. Like my build script in Visual Studio automatically un-registers and re-registers the dll when I'm making updates and debugging. The Advanced Installer, in the "Files And Folders" section, you can right click on the file and select Properties. In the properties dialog you can check "Auto Register" and select "Register .Net assembly for COM Interoperability". The help says this uses the RegAsm Tool to determine what to register, and then creates the Registry keys/values in the "Registry" section of the Install project.

After doing this to my DLL, I went to the "Registry" Section in Advanced Installer and only the HKCR key values existed. There was none of my custom entries that are created when I use regasm manually. I'm asking, does the Advanced installer use the RegAsm on INSTALL or does it use its internal "Registry" section to perform the registration.
Reason:
If it uses the Internal Registry Section, My DLL will NOT be registered correctly.
If on actual Installation it runs Regasm [APPDIR]\Mydll.dll only then will my DLL be registered correctly.

Thanks
J"SD"a'RR
jwest
Posts: 56
Joined: Tue Dec 27, 2005 12:14 am

Re: RegAsm & DLL Installation

Bump.

I have a dll that is marked with "Register .Net assembly for COM Interoperability"

It's an Excel addin so it has a <ComRegisterFunctionAttribute()> and a <ComUnregisterFunctionAttribute()> that contains calls to code that sets up the necessary registry entries.

AI does not seem to be calling RegAsm (or the equivalent) and my ComRegister function is not being called (I have a msgbox in it to let me know it has run)

In order to get the registration to work and my addin to run properly with Excel, I have to go to an elevated cmd prompt, change to [appdir] and run regasm manually after the AI setup msi finishes:

c:\Windows\Microsoft.NET\Framework\v2.0.50727\regasm my.dll

The result is that the expected msgbox from my custom registration code is displayed and RegAsm reports that the registration completed successfully. My addin then functions properly in Excel.

This setup is being run on a Win 7 x64 machine. This machine also has the trial version of Visual Studio 2010 installed if that makes any difference. (VS 2010 installs the .NET 4 framework)

My addin uses an older version of the .NET framework but is built with VS 2010 (on a different machine).

Here are the ComRegister and ComUnregister routines that are contained in the main class module of the addin which is contained in my.dll.

my.dll is marked with "Register .Net assembly for COM Interoperability" . These routines are not called when AI installs the dll. They are called when regasm is run:

Code: Select all

        <ComRegisterFunctionAttribute()> Public Shared Sub _
         RegisterFunction(ByVal t As Type)

            If bDebug Then
                MsgBox("Register: " & My.Application.Info.AssemblyName)
            End If

            Dim friendlyName As String = AppProductName
            Dim desc As String = AppProductName
            Dim loadBehavior As Integer = 3
            Dim commandLineSafe As Integer = 0

            Dim reg As New clsRegisterOfficeCOMAddin("Excel", AppProgId, False, True)

            Dim bAutomation As Boolean = True
            reg.RegisterAddinWithOfficeApp(friendlyName, desc, loadBehavior, commandLineSafe, bAutomation)

        End Sub

Code: Select all

        <ComUnregisterFunctionAttribute()> Public Shared Sub _
          UnregisterFunction(ByVal t As Type)

            If bDebug Then
                MsgBox("UnRegister: " & My.Application.Info.AssemblyName)
            End If

            Dim reg As New clsRegisterOfficeCOMAddin("Excel", AppProgId, False, True)

            Dim bAutomation As Boolean = True
            reg.UnRegisterAddinWithOfficeApp(bAutomation)

        End Sub
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: RegAsm & DLL Installation

Hello,

The "Register .net assembly for COM Interop" option does not actually call any bit of code. It simply extracts the necessary registries. You can try calling that code directly through a .net custom action.

Best regards
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
jwest
Posts: 56
Joined: Tue Dec 27, 2005 12:14 am

Re: RegAsm & DLL Installation

There are a couple of questions at the bottom of this post and I've provided a little background information here in the hope that it will help others who may find themselves using AI to deploy an Office COM Addin that was written in .net.

The issues outlined in this thread are not really Advanced Installer issues but they are significant for those of us that are attempting to use Advanced Installer to deploy an Office COM Addin that was developed in .NET. I'm upgrading a COM Addin developed in good old Visual Studio 98 to VS 2010 and .NET. The old addin uses Advanced Installer and it all works like a champ because the addin registration details specific to Excel are all handled by COM's DllRegisterServer mechanism.

When COM Registration fails in an MSI contains a decent explanation of some of these issues along with a caveat indicating that I should stay away from custom actions when deploying .net assemblies. Apparently, using RegAsm isn't as rollback safe and upgradable as using an MSI Installer where the required registry keys are included in the registry section of the MSI. There's also more information than you would ever want to know about the issues surrounding this situation here.

One challenge when installing an Excel COM Addin is that the registry locations vary depending on which version of Excel is installed on the target machine. These locations have to be determined at install time so you can't (at least, not easily) simply setup a bunch of predefined keys in the regitry section. It gets even worse if your COM Addin also provides Excel with user defined functions (as in an Excel automation addin) . This is why the ComRegisterFunctionAttribute function is so useful. Your code can dynamically create the registry entries at install time (thanks Microsoft) but it's only ever called from an MSI if you run RegAsm on your assembly via a custom action, which of course they don't recommend for the reasons stated above. Thanks Microsoft. Even Visual Studio itself runs RegAsm on your assembly when it builds it so it's ready to run and debug.

Questions

Having said that, I'm not about to abandon AI so what is the recommended way of calling RegAsm.exe [appdir]myAssembly.dll from a custom action within Advanced Installer? I have read that on 64-bit systems, you can't use vbscript to manipulate the registry from within a custom action and since I'll be targeting Excel x64 soon, I need a way to do this in my 64bit installer as well as the 32 bit version. Because I'm targeting Excel 2000 - 2010 and a specific version of .net (3.5) on Windows XP x32, Vista x32+x64 and Win 7 x32+x64, I need the custom action to run the correct version of RegAsm.exe from the appropriate location in the framework's directory structure. I've seen some examples that have a hard coded path to regasm.exe but thought there must be a prescribed way of identifying the correct version to run.

If I were to use a Visual Studio 2008 / 2010 generated setup, I could create an installer helper class with code that calls RegisterAssembly directly without the need to call RegAsm.exe. Is there an equivalent way to do this in AI?

Many thanks for your marvelous product.
JaedenRuiner
Posts: 12
Joined: Thu Apr 01, 2010 4:12 am

Re: RegAsm & DLL Installation

Alright,

Maybe I should just ask it this way:

I have the Files and Folders with the Folder of my installed DLL and the File of My Installed DLL.
I want to run RegAsm on my dll EXACTLY as if I was typing it in on the command line. So far every test has not worked, and the custom registration options that happen when I execute RegAsm from the command line are NEVER installed.

I've Tried:
PropertySource Custom Action - REGASM_20_PATH with the command line parameters pointing to my path and file
Launch FIle or URL - with the commandline set to [REGASM_20_PATH] /codebase [#MyFile]

and still nothing works.
What is the EXACT settings for the custom action so it operates the same as if I manually executed regasm myself. This means I HAVE TO HAVE the /codebase parameter to regasm.
Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
jwest
Posts: 56
Joined: Tue Dec 27, 2005 12:14 am

Re: RegAsm & DLL Installation

I noticed that one of the predefined custom actions is ".NET Installer Class Action". I wonder if this can be used to hookup an installer class used in a VB 2010 setup project, to AI?

Until I understand what the best way to proceed is, I created a small windows forms application (registeraddin.exe) in VB.net to do the equivalent of regasm. I found I had to compile it to x86 for it to work. I think this is because the assembly I'm trying to register is also compiled for x86. When I tried it and it was compiled for "Any CPU", the Register functions failed with "xxx is not a valid Win32 application".

Usage:
registeraddin.exe [/u] path\myassembly.dll

I simply include this as a file (registeraddin.exe) that is installed into the application folder and have added a new "installed custom action" for both the Install and Uninstall phases. The actions point to the registeraddin.exe file that was installed into appdir. The CA's command line is set to "[APPDIR]myAssembly.dll" for the install CA and to /u "[APPDIR]myAssembly.dll" for the uninstall CA. The double quotes are part of the command line as they are needed if there are any spaces in the path to the assembly file. The execution options used are "Synchronous execution - check return code", "deferred with no impersonation" and "Always execute".

This seems to be working for me although I have only tested it on Win 7 x64.

Here's the code if it helps.

Code: Select all

Imports System.Reflection
Imports System.Runtime.InteropServices

Public Class frmMain

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ' this app will only throw a UI if no command arguments are specified.

        Dim assToRegister As String ' full path and name of dll to register

        If My.Application.CommandLineArgs.Count = 0 Then
            ' if no arguments are passed assume we just want to register the assembly and hard-code the assembly file's path
            assToRegister = My.Application.Info.DirectoryPath & "\myAssembly.dll"
            If RegisterAssembly(assToRegister) Then
                MsgBox(assToRegister & " registered successfully", MsgBoxStyle.Information)
            End If
        ElseIf My.Application.CommandLineArgs.Count > 1 Then
            ' if more than one argument is specified then assume arg 0 is /u and arg 1 is the path
            assToRegister = My.Application.CommandLineArgs(1)
            UnRegisterAssembly(assToRegister)
        Else
            ' arg 0 is the path to the assembly's dll
            assToRegister = My.Application.CommandLineArgs(0)
            RegisterAssembly(assToRegister)
        End If

        Me.Close()

    End Sub

    Private Function RegisterAssembly(ByVal assemblyFile As String) As Boolean

        RegisterAssembly = False

        Try

            Dim asm As Assembly = Assembly.LoadFile(assemblyFile)
            If asm IsNot Nothing Then
                Dim regAsm As New RegistrationServices
                RegisterAssembly = regAsm.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase)
            End If

        Catch ex As Exception

            MsgBox("An error occurred while trying to register " & assemblyFile & vbLf & vbLf & ex.Message, MsgBoxStyle.Critical)

        End Try

    End Function

    Private Function UnRegisterAssembly(ByVal assemblyFile As String) As Boolean

        UnRegisterAssembly = False

        Try

            Dim asm As Assembly = Assembly.LoadFile(assemblyFile)
            If asm IsNot Nothing Then
                Dim regAsm As New RegistrationServices
                UnRegisterAssembly = regAsm.UnregisterAssembly(asm)
            End If

        Catch ex As Exception

            MsgBox("An error occurred while trying to unregister " & assemblyFile & vbLf & vbLf & ex.Message, MsgBoxStyle.Critical)

        End Try

    End Function

End Class

Return to “Common Problems”