Friday, April 22, 2005

VisualStudio.Net Add-in written in Delphi

I'm planning to create a spin-off of UnCodeX (again), this is going to be an add-in for VisualStudio.Net. Right now Epic has a simple tool that gives a class and package tree, but compared to UnCodeX is kinda inferior. Since I have a lot of base code it would be easy to create an add-in right?

Well not completely, first the add-in creation is done via an wizard in VisualStudio, well great, but how would I do the same in Delphi?. The add-ins are all COM based, so I will have to import a type-library somewhere. The VS.Net wizard does all the base work, so I have a few pointers, like what interfaces I should implement. But I have no idea what type-libraries to import. After a long search and some pointers here and there I've found out how to create a Add-in for VS.Net in Delphi.

  1. Before you do anything you will first have to import and install the type libraries (to make things easier in the next few steps).
    1. Import and install the type library: Microsoft Add-Iin Desginer, the actual file is called: MSADDNDR.DLL.
    2. Import and install the type library: Microsoft Development Environment 7.0, the actual file is called: dte.olb.
    Make sure you installed them in a package.
  2. Now create a new ActiveX library; nothing major here, you just need it.
  3. Now in your library create a new ActiveX Automation Object.
    1. Enter any name you like; different from your library name.
  4. You will now see the Type Library tool, select your library in the tree and open the Uses tab.
    1. Right-click the list and "show all type libraries"
    2. Now select the same type libraries you previously installed.
  5. Now select the Automation Object you created (it's the one not prefixed with an I)
    1. Select the Implements tab
    2. Right click and add _IDTExtensibility2
    3. Right click and add AddIn
    4. If either one of these are not available you messed up in the previous steps.
  6. Close the type library tool window.
  7. Save the new unit (Save all files i the project)
  8. Now add the following to the interface uses list: , EnvDTE_TLB, AddInDesignerObjects_TLB
  9. If everything is ok you should be able to compile the library.
  10. After the compile is done you should register the library via the menu Run -> Register ActiveX Server
  11. Now you will have to add an entry to the registry so the add-in will show up in the Add-in manager. Add a new key to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\7.1\Addins\. The key name should be: <library name without extention>.<automation object name>
  12. The add-in should now be visible in the add-in manager

If you want to change the descript and version information in a later stage just open the .tlb file in Delphi. This will pop-up the type library tool.

These are just the basics for a add-in, how the rest works is still a mystery, but I hope to solve it soon and report it here. Next thing might be how to add your own tool window, I assume this can done via an ActiveForm. The tool windows are refered to via the GUID in VisualStudio.NET, so it would be some more ActiveX\COM stuff.