How to write a simple DXCore plug-in

DevExpress the creator of Refactor and CodeRush two great visual studio productivity tools provide a free library called DXCore that can be used to create rich plug-ins that can extend visual studio the same way their commercial products do. Until visual studio 2010 will be widely developers can use DXCore to extend visual studio and provide integration functionality without messing around with DTE and GUIDs.

In this tutorial I will explain what is needed to write your first DXCore plug-in

Prerequisites

  1. We need visual studio (not express) to write the plug-in, either vs2008 or vs2005 will do.
  2. DXCore – download CodeRush evaluation go run the installer and choose to install DXCore. you can install CodeRush and refactor as well if you want to try them for size.

When running visual studio you will be prompted to choose the location of your community plug-ins. this is where your plug-ins will be placed.

Now we can write our first DXCore plug-in.

Creating the plug-in

Notice that a new tool menu named DevExpress was added to VS, click on it and choose New Plug-in, or create a new project of type DXCore (using File –> new project).

image

Choose your language of choice (C#), standard plug-in and the plug-in name.image

Select a name and check “Load Manually”, This tells DXCore not to load the plug-in automatically to Visual Studio, this option is only relevant to the development phase.

image

Now we have a new plug-in that does absolutely nothing, it’s time to add some functionality.

Writing the code

DXCore adds a few new tools to VS toolbox, in this tutorial we’re going to use the “Action”.

Simply drag a new action into the designer.

image

Add name and description in the action property page:

image

Double click on the action or create an “Execute” event handler and paste this code inside:

image

The first line we get the position of the caret on the screen. Then we get the active element and use it to receive the current opened document which we use to write text of the screen. 

Running the our code

Pressing F5 (Run Debug) will open a new instance of VS, open or create a new C# project so we’ll have some where to try our new plug-in.

Open the Plug-in manager and double click the Plug-In to enable it (remember the “Load manually” checkbox).

image

Lastly we want to bind a new keyboard shortcut that will invoke our code. Inside DevExpress –> options choose Shortcuts (under IDE)

image

Select a proper shortcut and bind it to the action’s name:

image

That’s now we can run our code, each time I press the key combination a remark is written in my code:

image

Additional Resources

You can learn (much) more about DXCore in the following places:

Rory Becker has posted several tutorials about DXCore on his blog.

Travis Illig also written a few tutorials and how-tos on his blog.

DXCore community plugins on Google Code.

If you’re stuck with a tough problem DevExpress Forums is the place to ask DXCore related questions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s