Use Visual Studio Setup Project to automatically register and GAC a COM Interop DLL

32,699

Gacutil.exe won't be available on the target machine. Not a problem, MSI can get the job done. Right-click "File System on Target Machine", Add, GAC. Right-click that added folder, Add, Project Output. That ensures the assembly is gac-ed.

It can also register the assembly like Regasm.exe does. Set the Register property of the project output reference to vsdrpCOM.

Share:
32,699

Related videos on Youtube

Ben McCormack
Author by

Ben McCormack

Becoming a better version of myself. Website: http://benmccormack.com Twitter: @bmccormack I find great satisfaction in developing solutions that make it easier and simpler for people to do their jobs. I haven't updated by Stack Overflow CV in forever, so check out my LinkedIn page.

Updated on July 09, 2022

Comments

  • Ben McCormack
    Ben McCormack almost 2 years

    I've created a .NET assembly for COM interop and it is working well on my development machine. I'm currently trying to figure out how to deploy the DLL to a target machine using Visual Studio's "Setup Project." How can I use the VIsual Studio setup project to do the following things:

    • Register the assembly (currently using regasm).
      • The assembly needs to be registered successfully and the type library (.tlb) needs to be registered successfully.
      • This answer suggests scrapping regasm in favor of custom code. I this is a good idea? If so, how does this code get included in the setup project?
      • This answer suggests using the /regfile command of regasm and then using the import tool on the Registry in the Setup Project. Will this work?
    • Install the assembly in the GAC (currently using gacutil)
      • I'm aware of the "Global Assembly Cache Folder" in the "File System on Target Machine." Is there anything special I need to do in including the assembly in the setup project?

    Any other advice or concerns would be much appreciated.

  • Ben McCormack
    Ben McCormack about 14 years
    Will the register property being set to vsdrpCOM automatically create and register the .tlb file as well? If not, how do I include the .tlb in the set up project (it doesn't seem to like being shared in the GAC folder in the setup project)?
  • Ben McCormack
    Ben McCormack about 14 years
    That's a great point. I got so used to typing regasm /tlb... that I just assumed I would need it, but you bring up a great point - the client machine's won't be writing code against these assemblies. Much thanks.
  • Keith
    Keith about 13 years
    To answer Ben's question in his comment, using vsdrpCOM will automatically create and register the .tlb file.
  • rank1
    rank1 about 10 years
    So what You are saying is that just setting register property to vsdrpCOM does exactly the same as the whole long solution in here? stackoverflow.com/questions/239465/… if so, then absolutely brilliant!
  • rank1
    rank1 about 10 years
    To conifrm: to make the Regasm automatic both steps from Hans Passant answer needs to be done.
  • rank1
    rank1 about 10 years
    I got tlb generated only into the Debug folder. What might be the reason? Everything works fine under Debug installer, under release there is no .tlb file generated by installer
  • Ehsan Sajjad
    Ehsan Sajjad over 5 years
    Thanks @Hans, it really saved me today, was unable to figure out why the COM interop dll is not working after making installer.