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.
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:
- Download the project template ZIP file from here.
- 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#.
- 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.
Powertoys Examples Solution
The following was done with VS2005, Resharper 3.1, and Powertoys VS 9.0.
- Download and install Resharper Powertoys example solution from here.
- 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.
- 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.
- Compile the solution.
- To install any of the plugins (for example 'CyclomaticComplexity'):
- 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.
- Copy the plugin's assembly to this folder. e.g. 'CyclomaticComplexity.dll' (I also copy the pdb file 'CyclomaticComplexity.pdb').
- Make Resharper discover this plugin by:
- Close Visual Studio.
- Open regedit and locate key HKEY_LOCAL_MACHINE\SOFTWARE\JetBrains\ReSharper\v3.1\vs8.0\.
- Change 'One-Time Initialization Generation' value to current time date.
- Start Visual Studio. View the list of plugins from the Resharper menu.
Available Plugins
- Powertoys
- Agent Johnson Plugin
- Agent Smith Plugin
- Localization Plugin
- NHibernate Plugin
- Resharper NHibernate plug-in
- Resharper.TestDrive
- Localization - RGreatEx (commercial)
- Localization - RGreatEx (commercial), another link
- MbUnit
- Source Analysis for ReSharper
- VstsUnit Plugin for ReSharper
Useful Links
- Resharper - List of plugins
- Resharper 3.0 - Plugin Development
- Resharper 2.5 - Plugin Development (has better documentation)
- Resharper - OpenAPI Support Forum
- Resharper - Deploying Plugin
- Getting Started with ReSharper OpenAPI (CodeProject)
Child pages: