Announcement

Collapse
No announcement yet.

How do I register a .Net dll for COM interop?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I register a .Net dll for COM interop?

    Hi,

    I'm trying to figure out a way to install a .Net dll for COM interop so that it gets registered correctly in the MSI way, and I'm not sure how to do it using MSIFactory. Ideally I'm looking for a step by step idiots guide to this.

    At the moment I have the dll, and the related tlb and reg files that I created using RegAsm, and now I just want to put them all together using MSIFactory.


    I currently include the dll and the tlb in the install files but I'm not sure how to get them registered correctly. The TypeLib properties screen confuses me as I thought all of this information would have been inside the tlb file anyway, the COM Class properties screen also confuses me for the same reason. All the information I have found points to using the vsdraCOM or vsdrfCOM options but I have no idea how these compare to MSIFactory.

    Help!

  • #2
    Hello,

    unless I am missing something here, I think you could double-click the dll you wish to register, then in the Properties dialog click the Registration tab, and set the Other > .NET checkbox. What have you set for the TypeLib? (Is it needed to register it?)

    Ulrich
    Last edited by Ulrich; 08-05-2009, 04:02 PM.

    Comment


    • #3
      It doesn't work. I double-click on the file, go to registration, select Other, .NET/Win32 Assembly.

      From there I select
      Assembly Type - .NET
      Registration Type - Private
      Application file - the installed dll
      Manifest is left blank
      Automatically read from assembly is checked.

      When I run the installation and then attempt to create a reference to the code object I get an application defined or object not set error.

      If I manually run RegAsm.exe on the machine against the dll I have installed with the /register /codebase arguments I can then reference the application correctly.

      Am I just doing something wrong here?

      Comment


      • #4
        Maybe you could use this approach, placing the script in a custom action.

        Ulrich

        Comment


        • #5
          Unfortunately that is not the recommended way of updating the registry as the MSI has no information on what gets changed, so it can't roll it back in the event of a failure. The idea of using tbl and / or reg files is the msi database can get all of the registry changes from here.

          Is there no equivalent of vsdraCOM or vsdrfCOM within MSIFactory?

          Comment


          • #6
            Maybe you could generate the reg file file with RegAsm, and import that into the installer?

            RegAsm /regfile[:Filename]

            Ulrich

            Comment


            • #7
              Kind of. Here are the steps that I needed to do to get it installed:

              Pre-install work:
              1. Create the relevant library files and store them in a folder.
              2. To generate the required tlb files from the library files, run the following batch command for each file:
              "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Reg Asm.exe" /nologo ".\LibraryFile.dll" /tlb:".\LibraryFile.tlb"
              This will create the tlb file in the same directory as the dll file.

              3. Create the registry files. These are different dependent on if the files are to be installed to the GAC or not.
              GAC install
              Run the following batch command for each file:
              "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Reg Asm.exe" /nologo ".\LibraryFile.dll" /regfile:".\LibraryFile.reg"
              This will create the .reg file that can be imported straight into the installer package.

              Private Install
              Run the following batch command for each file:
              "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Reg Asm.exe" /nologo /codebase ".\LibraryFile.dll" /regfile:".\LibraryFile.reg"
              This will create the .reg file that needs to be modified before it can be imported into the msi.
              Use edit/replace on the reg file and replace the explicit location of the dll with the msi variable of [INSTALLDIR].
              For example change:
              "CodeBase"="file:///C:/Documents and Settings/username/Desktop/Support/LegacyAPI/LibraryFile.dll"
              to
              "CodeBase"="file:///[INSTALLDIR]/LibraryFile.dll"
              This is now ready to be imported into the msi.

              Install Work:
              4. Open MSI Factory for the files and add the tlb and dll files.
              5. For each dll file, double-click the component, select the 'Registration' tab and from other select the '.Net/Wind32 Assembly' option. Click 'Edit' if the screen doesn't automatically appear.
              6. Set the following properties:
              Assembly Type: .NET
              Registration Type:
              For GAC: 'Global Assembly Cache'
              For private files: Private, set the Application file to be the source dll.
              Leave the Manifest file blank.
              Strong Assembly Cache Attributes: Select 'Automatically read from assembly'.

              7. Click OK, and OK to get back to the main window.
              8. From 'System Editors', select 'Registry',
              9. From the Registry window select 'Import, .Reg File...'.
              10. Browse to the reg file and import the the data. Click OK to get back to the main screen.

              The registration part of the install should now be ready.

              Comment


              • #8
                Slight change to point 2 above:
                When you use RegAsm.exe to create the tlb files it will automatically update the registry on the build machine with the values. To get around this use TlbExp.exe instead. This is part of the Windows .Net SDK and is available from the Microsoft download site.

                Replace point 2 above with point 2 below:

                2. To generate the required tlb files from the library files, run the following batch command for each file:
                ".\TlbExp.exe" /Win32 /nologo ".\LibraryFile.dll" /out:".\LibraryFile.tlb"
                This will create the tlb file in the same directory as the dll file.

                Comment


                • #9
                  We have found that this doesn't work either as TlbExp.exe doesn't create the correct registry settings for the COM events that are raised. This gives us the error of "Object does not match target type" when errors are raised from the application.

                  The solution? Use Visual Studio to create the MSI as this allows us to register the tlb files correctly that contain the event declarations.

                  Comment

                  Working...
                  X
                  😀
                  🥰
                  🤢
                  😎
                  😡
                  👍
                  👎