ReSharper 9 添加菜单项操作不起作用

ReSharper 9 Adding menu item action not working

尝试更新我的 resharper 扩展以适用于 9.0,之前我只是将 dll 移动到插件目录,但现在我需要弄清楚如何让 nuget 工作...我已经能够打包文件,dll 包含在 nupkg 中,但我认为我有一些 namespace\id 问题(对 .net 不是很熟悉)而且我的 actions.xml 似乎没有被阅读resharper 当我导入 nuget 包时。未添加菜单项。 Anwyays 如果有人可以给我任何关于如何调试 nuget 包或可能出错的建议,我将非常感激,因为我已经坚持了几天了。

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 规范

<?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>

动作的注册方式在 ReSharper 9 中发生了变化。它不再通过 actions.xml 完成,而是通过动作的接口完成 class。例如,要将操作添加到 ReSharper → 工具菜单,您可以:

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

您还需要为 Id 指定一个唯一值。从 9.1 开始,这需要在您自己的扩展中是唯一的(9.0 要求它在整个安装中是唯一的,包括 ReSharper 本身和任何其他扩展)。

每当您更改动作的属性或接口时,都需要通过 nupkg 重新安装扩展(动作静态注册到 Visual Studio,与标准 VS 扩展的方式相同),但是如果只是实现发生了变化,您可以手动或通过 a small change to the .csproj.

将 dll 复制到安装文件夹

您还需要确保已定义 ZoneMarker class。这声明您的操作属于一个区域,该区域用于 enable/disable 基于已安装功能和当前主机的功能(例如,因此 Visual Studio 特定扩展仅在 VS 中工作,不会加载到 dotPeek 中, ETC。)。您可以了解有关 Zones in the devguide, with this page providing useful info for defining a zone marker.

的更多信息

This thread 应该也有帮助。

此外,将 dll 和 nupkg 命名为 JetBrains.ReSharper.(Whatever) 以外的名称可能是个好主意,以防止与官方 dll 发生任何潜在冲突,并防止混淆 dll 的来源。名称的第一部分应该是您的公司名称(或个人名称)。