Resharper Plugins

Introduction

I could not find much documentation on writing Resharper plugins and I've had to do some googling and guessing to work some of it out. Here are my notes.

Google search words: resharper openapi plugin powertoys

Child pages:

Plugin Ananotmy

On a 'One-Time Initialization Generation' Resharper scans assemblies in its bin folder. A plugin will have, as a minimum:

  • An AssemblyInfo.cs file with Reshaper plugin configuration attributes.
  • Conguration XML file (typically named 'Actions.xml') as a embedded resource in the assembly.
  • Action handler class decorated with the [ActionHandler] attibute.
ResharperConfig.jpg

AssemblyInfo.cs

The AssemblyInfo.cs Resharper plugin attributes are:

[assembly: PluginVendor("My Vendor Name")]
[assembly: PluginDescription("Plugin description.")]
[assembly: ActionsXml("MyNameSpace.Actions.xml", Precompile = false)]

Most importantly the [ActionsXml] attribute value must use the project's default namespace to enable the Actions.xml file to be located within the assembly as an embedded resource.

Configuration XML File

The configuration XML file configures:

  • In which menu/context items the plugins commands will appear.
  • The menu item text.
  • An action ID which identifies the action class that will be used via an [ActionsXml] attribute.

For example:

<?xml version="1.0" encoding="utf-8" ?>
<!--   This file is a modified version of one supplied in Resharper's PowerToys example solution.
         Modifications copyright (c) Robert Smyth 2008. See project's license. -->
<actions>
  <insert group-id="ReSharper" anchor-id="ShowHelp" position="before">
    <separator/>
    <action id="AddMenuItem.MyPluginName.MyActionName" text="== Put your menu item text here =="/>
  </insert>
 
  <insert group-id="VS#Code Window" position="last">
    <separator/>
    <action-ref id="AddMenuItem.MyPluginName.MyActionName" />
  </insert>
 
</actions>

Action Handler Class

An action handler class is identified by an [ActionsXml] attribute. The attribute's string pramater must match an ID in the Actions.xml file for the class to be used.

For example:

[ActionHandler("AddMenuItem.MyPluginName.MyActionName")]
internal class MyPluginAction : IActionHandler
{
  :

Creating A Plugin

To creat a new Resharper plugin using the VS2005 project template found from the TheProbe project downloads:

  1. Download the project template ZIP file from here.
  2. Copy the ZIP file to your Visual Studio template area. e.g. (for Vista) C:\Users\Robert\Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual C#.
  3. You can now create a Resharper plugin project by Add | New Project… command and select the Visual C# tree node. The template will appear on the right as shown below.
flickr:2687943391

Powertoys Examples Solution

The following was done with VS2005, Resharper 3.1, and Powertoys VS 9.0.

  1. Download and install Resharper Powertoys example solution from here.
  2. Move Powertoys code from (typically) C:\Program Files\JetBrains\ReSharper\v3.0\vs9.0\PowerToys to your source code area. Windows Vista will hinders using source code in a C:\Program Files folder.
  3. Open the solution, it will complain that a file is missing. Known fault, remove the project with the missing file from the solution, or do a Google to find it.
  4. Compile the solution.
  5. To install any of the plugins (for example 'CyclomaticComplexity'):
    1. Create a folder (if not already there) for the plugin in Resharper's bin folder (typically: C:\Program Files\JetBrains\ReSharper\v3.0\vs9.0\Bin). e.g. C:\Program Files\JetBrains\ReSharper\v3.0\vs9.0\Bin\Plugins\CyclomaticComplexity.
    2. Copy the plugin's assembly to this folder. e.g. 'CyclomaticComplexity.dll' (I also copy the pdb file 'CyclomaticComplexity.pdb').
  6. Make Resharper discover this plugin by:
    1. Close Visual Studio.
    2. Open regedit and locate key HKEY_LOCAL_MACHINE\SOFTWARE\JetBrains\ReSharper\v3.1\vs8.0\.
    3. Change 'One-Time Initialization Generation' value to current time date.
    4. Start Visual Studio. View the list of plugins from the Resharper menu.

Available Plugins

Useful Links


Child pages:

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License