Run and Test Plug-In Scripts from Visual Studio

Testing Plug-in Scripts

Testing plug-in scripts in Eclipse is annoying at best. For one, any time you make a change to the script you need to re-start Eclipse, or it’ll lock up your script DLL and won’t even let you compile.

Another problem with running your script in Eclipse is that you can’t use the debugger (easily). It would be nice if you could just press F5 in Visual Studio and run your script, set up breakpoints, or step through your code line by line.


To help with these problems, Eduardo Acosta (a former software developer at the University of Michigan, now at Varian) wrote PluginTester, available at the Varian Developers Forum.

PluginTester is a stand-alone app that creates an Eclipse Application object and calls your script’s main method. If you add the PluginTester project to your solution, you can run it from Visual Studio and step through the code, including yours.

PluginTester is a great tool for running and debugging your scripts, but it has one drawback: it requires that you edit its code to specify the method to call in your script. And you need to do this for every new script you write.


To address this drawback, I wrote a new tool based on PluginTester, which I’ve creatively called EclipsePlugInRunner. You don’t need to modify its code in order to run your script. Additionally, your script doesn’t need to know about EclipsePlugInRunner. In other words, neither library references the other. After all, the tool is there only for running it from Visual Studio and won’t be needed once your script is running in Eclipse.

I’ve made the source code available on GitHub: EclipsePlugInRunner. But the best way to start using it is through NuGet. First, open a plug-in script you’d like to run in Visual Studio. Add the following method to your Script class:

This method is now your “main” method, so any code that used to be in the Execute method should go here. Notice that there’s no ScriptContext anymore. EclipsePlugInRunner will call the Run method, but because it can’t create a ScriptContext object, it needs to pass the context members individually. This means that you’ll need to either (1) modify any code that uses the ScriptContext to use the member objects instead, or (2) create your own wrapper to contain the context members and use it instead.

The Execute method should now just call the Run method and pass the appropriate members:

Now, add a new WPF Application project to your solution. If your script’s project is named MyScript, you can call the WPF project something like MyScript.Runner. Remove the MainWindow.xaml file, which will also remove the associated MainWindow.xaml.cs file.

Right-click on the WPF project and select “Manage NuGet Packages…” Search for “esapi” and you should see the EclipsePlugInRunner package. Install it.

Right-click on the WPF project again and select “Add Reference…” Choose the “Projects” item on the left bar, and check the project that contains the main Script class.

Open the App.xaml file and replace the StartupUri line with the following:

Open the App.xaml.cs file and add the following handler:

Make sure that you’ve added the correct using statements (in this case, EclipsePlugInRunner.Scripting and VMS.TPS). That’s it. EclipsePlugInRunner uses the x64 ESAPI assemblies, so you’ll need to set the WPF project’s CPU to x64 as well. Also, set the project as the “Start Up” project.

Running Your Script

When you start the application, you’ll be prompted for your username as password. These are the same you use to log in to Eclipse. A window will show up, which looks somewhat similar to PluginTester:


Enter the patient ID1, click Open, and choose the PlanSetup(s) or PlanSum(s) you’d like to be in scope. Then, choose the PlanSetup that you’d like to be active. Click on Run and your script will run with the context you’ve chosen (you can also double-click on the active PlanSetup in order to run your script).

Recent contexts will be displayed at the top, where you can double-click on one and quickly run your script with that context. If you click on Open for a recent context, you’ll be able to modify the context and run the script with that. Recent contexts are automatically saved in the bin\Debug or bin\Release directory of the WPF Application in your project.

When you’ve run your script and then closed it, you’ll go back to the Runner window. You may open another patient or context and run the script again. If you want the Runner window to automatically close when you close your script, choose the “Exit after plug-in script ends” option at the bottom.

Open Source

EclipsePlugInRunner is open source, so you can submit issues, fork it, or send pull requests. It’s not a finished product and can use many improvements. Feel free to contribute!

2 thoughts on “Run and Test Plug-In Scripts from Visual Studio

    1. Carlos Anderson Post author

      Hi Albert,
      EclipsePlugInRunner uses the Window object that’s obtained via the Execute method. This Window object is a WPF class, so I don’t believe you can use it with WinForms. However, feel free modify EclipsePlugInRunner so that it optionally uses the Execute method without the Window object. This would allow you to create your own WinForms windows.
      — Carlos


Leave a Reply

Your email address will not be published. Required fields are marked *