Creating plugins for dotPeek

In a previous post, we’ve seen that dotPeek supports creating and loading plugins. The NuGet plugin for dotPeek is a good example to demonstrate how to get started creating plugins for dotPeek. Sources for this plugin are available on GitHub. But let’s create a plugin of our own!

Before we start: dotPeek does not have a formal SDK yet. However it shares a lot of commonalities with ReSharper. In fact: dotPeek is built on the same platform as ReSharper reusing the project model, PSI, navigation and so on. Which is good news: we can use the ReSharper SDK (see the downloads page) to create plugins for dotPeek. Another option is to start from a class library project and work with a small NuGet package I’ve created to help you get started.

Creating a new plugin

To create a plugin for dotPeek, we can make use of the instructions provided with the ReSharper SDK. This involves a lot of project modifications so we’ll take the easy way out: we can create a dotPeek plugin by installing a NuGet package.

Install-Package JetBrains.DotPeek.PluginDevelopment

In Visual Studio, we can start out with a new Class Library project, making use of .NET 3.5 or up. Next, we can install the JetBrains.DotPeek.PluginDevelopment NuGet package into the project. This NuGet package will convert the class library we have into a dotPeek plugin by adding assembly references and several attributes. Note that the NuGet package will target the latest version of dotPeek that is installed on your system (which also means we have to have a copy of dotPeek installed).

That’s everything we have to do: by running our project, dotPeek will launch with our fresh plugin loaded:

New plugin for dotPeek

Now let’s see where those menu items are coming from…

Menus, toolbars and handlers

Menu items, like the About menu we saw when loading our plugin in dotPeek, are triggered using handlers. The AboutActionHandler.cs file in our project is a sample handler implementation.

About action handler

There are some things to note here:

  • The ActionHandler attribute denotes the fact that this class is a handler with a specific name, “MyFirstDotPeekPlugin.AboutAction” in this case.
  • Handlers are added to menus and toolbars in the Actions.xml file, referencing the action name. More information on actions.xml can be found in the ReSharper plugin documentation. To make working with Actions.xml easier, the NuGet package also added an Actions.xsd containing the full XML schema we can use.
  • Handlers implement two methods of the IActionHandler interface:

    • Update – specifying whether the action is enabled or disabled.
    • Execute – the code which is executed once an action is being invoked.

    The following handler will be always available and can open a new command dialog when invoked:

    Command line tool window in dotPeek

    We can add it to a menu or toolbar by updating the actions.xml file:

    Actions.xml for plugins

    Distributing a plugin

    There comes a time when we want to make our plugin available to the public. Distributing a plugin is a simple process:

    • Distribute the assembly compiled from your project
    • Users can copy this assembly into %LOCALAPPDATA%JetBrainsdotPeekv<your target dotPeek version>plugins

    Another option is to generate a simple installation batch file, check my NuPeek plugin’s GitHub repository for more information.

    Further reading

    In this blog post, we’ve only scratched the top of the surface. With plugins, a lot of things are possible: we can add menu items, toolbar buttons, tool windows, options panes and so on. In fact, many of the features shipped with dotPeek are in fact built as plugins. It is advised to consult the ReSharper Plugin Development Guide for additional information on developing dotPeek plugins.

    This entry was posted in dotPeek Tips&Tricks and tagged , , , . Bookmark the permalink.

    3 Responses to Creating plugins for dotPeek

    1. Abhijit says:

      I have installed JetBrains DotPeek on my laptop. I fired up Visual Studio 2010 and installed the JetBrains.DotPeek.PluginDevelopment package. So far so good.

      Then when i attempt to compile the assembly, I get the following errors:

      The type or namespace name 'ActionHandlerAttribute' could not be found (are you missing a using directive or an assembly reference?)
      The type or namespace name 'ActionHandler' could not be found (are you missing a using directive or an assembly reference?)
      The type or namespace name 'ActionHandlerAttribute' could not be found (are you missing a using directive or an assembly reference?)
      The type or namespace name 'ActionHandler' could not be found (are you missing a using directive or an assembly reference?)
      The type or namespace name 'JetBrains' could not be found

      Where are these namespaces located? I could not find a link to the ReSharper SDK, though I did find this
      link

      Please help in getting my project to compile. I am using Visual Studio 2010 and DotPeek version

      JetBrains dotPeek 1.1
      Build 1.1.1.33 on 2013-08-09T01:25:56

      No license required
      Plugins: none

      Copyright © 2011–2014 JetBrains s.r.o. All rights reserved.

      • Maarten Balliauw says:

        These namespaces are in the dotPeek assemblies, ActionHandlerAttribute is in JetBrains.Platform.Resharper.UI

        It’s probably best to reference (from the dotPeek installation folder):

        dotPeek.dll
        JetBrains.Platform.ReSharper.ActivityTracking.dll
        JetBrains.Platform.ReSharper.ComponentModel.dll
        JetBrains.Platform.ReSharper.DocumentManager.dll
        JetBrains.Platform.ReSharper.DocumentModel.dll
        JetBrains.Platform.ReSharper.IDE.dll
        JetBrains.Platform.ReSharper.Interop.WinApi.dll
        JetBrains.Platform.ReSharper.Metadata.dll
        JetBrains.Platform.ReSharper.ProjectModel.dll
        JetBrains.Platform.ReSharper.Shell.dll
        JetBrains.Platform.ReSharper.Symbols.dll
        JetBrains.Platform.ReSharper.TextControl.dll
        JetBrains.Platform.ReSharper.UI.dll
        JetBrains.Platform.ReSharper.UI.Standalone.dll
        JetBrains.Platform.ReSharper.Util.dll
        JetBrains.ReSharper.Features.Browser.dll

    2. Abhijit says:

      Thank You. That has enabled me to compile the plugin.
      Also this requires .NET 4.0.
      This won’t work with .NET 3.5
      One of the references System.Xaml does not exist for .NET 3.5

    Leave a Reply

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

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>