Testing and debugging your Enterprise Architect C# Add-In

In my previous post Tutorial: Create your first C# Enterprise Architect add-in in 10 minutes I explained how to create a simple add-in for Enterprise Architect.

(Smoke) testing your add-in

Once created you will of course want to test it to see whether it works.

The logical thing to do is fire up Enterprise Architect and try it out. And then, as it goes with software development, you discover a bug, or a missing feature.

Next thing you do is correct the problem, build the project… and get an error, because the add-in dll is being used by Enterprise Architect and it can’t be overwritten by Visual Studio.

So you close EA, build the project, open EA, find another issue,… rinse and repeat

After a while this whole process becomes a major annoyance that is really crippling your productivity.

Debugging your add-in

Debugging an add-in for Enterprise Architect is only possible when you have a full (payed) version of Visual Studio.

To debug your add-in (using a full version of VS) you set the appropriate breakpoints, start EA, and in Visual Studio choose Debug|Attach to process. Then choose ea.exe and start the functionality of your add-in. Visual Studio will then stop the execution of your add-in code at the breakpoints you defined, and you can debug away.

But again, if you change anything to the code, and want to re-build you’ll need to shut down EA first.

When you have a (free) Express version of Visual Studio you’re completely out of luck, since Microsoft decided not to include the “Attach to process” feature in the Express versions. (see Wikipedia for more details about he limitations of the Express versions)

The solution

To avoid this problem I wrote a small add-in test application that mimics the menu behavior of EA and allows you to test, debug and build your add-in without having to shut down and restart EA.

This add-in tester will only allow you to test and debug the menu driven functionality of your add-in. To test and debug the event driven functionality (things like EA_OnPostNewElement you will still have to resort to the annoying way of working)

Here’s what you need to do to use the test application

  • Download the source code from the Sparx Systems Community Site
  • Add the EAAddinTester project to your Visual Studio
  • Set the EAAddinTester project as Startup Project
  • Add a reference to your add-in project to the EAAddinTester project
  • Change the first line of code of the EAAddinTesterProgram.cs so it points to your add-in class
    // replace this next line with the addin you want to test
    internal static MyAddin.MyAddinClass addin = new MyAddin.MyAddinClass();
  • Disable your add-in in Enterprise Architect via Add-Ins|Manage Add-Ins…
  • There is an excellent tool available to enable/disable add-ins while starting up EA: Enterprise Architect Launcher
  • Shut down and restart EA
  • Hit F5 to start-up the EA Add-in Tester

Now choose the location of your menu and you should see the menu’s you’ve defined for your add-in.

Selecting a menu option will execute the appropriate functionality of your add-in just like EA would.

Using this tool will of course also solve the debug issue for Visual C# Express users.