Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper 9 Adding menu item action not working

Trying to update my resharper extension to work for 9.0, before I was just moving the dll into the plugins directory but now I need to figure out how to get nuget to work... I've been able to package the files, dll gets included in the nupkg but I think I have some namespace\id something something issues(not very familiar with .net) and it doesn't seem as if my actions.xml is even being read by resharper when I import the nuget package. The menu item isn't being added. Anwyays if anyone can give me any sort of advice on how to debug a nuget package or what might be going wrong would really really appreciate as I've been stuck on this for a few days now.

Actions.xml

<?xml version="1.0" encoding="utf-8" ?>
<actions>
  <action id="yuval" text="L10N"></action>
  <insert group-id="ReSharper" position="last">
    <action-ref id="yuval" text="About Localization Helper"/>
  </insert>
</actions>

AboutAction.cs

namespace JetBrains.Resharper.L10N
{
    [Action(Id)]
    public class AboutAction : IExecutableAction
    {
        public const string Id = "yuval";

    public bool Update(IDataContext context, ActionPresentation presentation, DelegateUpdate nextUpdate)
        {    
            return true;
        }

        public void Execute(IDataContext context, DelegateExecute nextExecute)
        {
            MessageBox.ShowMessageBox(
              "Localization Helper\nYuval\n\nHelps Localize",
              "About Localization Helper",
              MbButton.MB_OK,
              MbIcon.MB_ICONASTERISK);
        }

    }
}

nuget spec

<?xml version="1.0"?>
<package >
  <metadata>
    <id>JetBrains.Resharper.L10N</id>
    <version>1.0.0.7</version>
    <title>L10N</title>
    <authors>Yuval</authors>
    <owners>UW</owners>
    <licenseUrl>https://myurl.com</licenseUrl>
    <projectUrl>https://myurl.com</projectUrl>
    <iconUrl>https://myurl.com/logo.png</iconUrl>
    <requireLicenseAcceptance>true</requireLicenseAcceptance>
    <description>Tool to help localize</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2015</copyright>
    <tags></tags>
    <dependencies>
      <dependency id="Wave" version="[1.0]" />
    </dependencies>
  </metadata>
<files>
    <file src="..\bin\Debug\JetBrains.Resharper.L10N.dll"
          target="dotFiles\"/>
  </files>
</package>
like image 913
Mr Boss Avatar asked Feb 22 '26 07:02

Mr Boss


1 Answers

The way actions are registered has changed in ReSharper 9. It's no longer done with actions.xml, but with interfaces on your action class. For example, to add an action to the ReSharper → Tools menu, you would do:

[Action(ActionId, Id = 1)]
public class AboutAction : IExecutableAction, IInsertLast<ToolsMenu>
{
  public const string ActionId = "yuval";
  // …
}

You also need to specify a unique value for Id. As of 9.1, this needs to be unique within your own extension (9.0 required it to be unique across the whole installation, including ReSharper itself and any other extensions).

Whenever you change the attributes or interfaces of an action, the extension needs to be reinstalled via nupkg (the actions are statically registered with Visual Studio, in the same way as a standard VS extension), but if just the implementation has changed, you can copy the dlls to the install folder, either manually, or via a small change to the .csproj.

You also need to make sure you've defined a ZoneMarker class. This declares that your action belongs to a zone, which is used to enable/disable functionality based on installed features and the current host (e.g. so Visual Studio specific extensions only work in VS and don't get loaded into dotPeek, etc.). You can find out more about Zones in the devguide, with this page providing useful info for defining a zone marker.

This thread should help, too.

Also, it's probably a good idea to name you dll and nupkg something other than JetBrains.ReSharper.(Whatever) to prevent any potential clashes with official dlls, and to prevent confusion as to where the dll comes from. The first part of the name is supposed to be your company's name (or personal name).

like image 88
citizenmatt Avatar answered Feb 24 '26 20:02

citizenmatt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!