Binding 如何让Resharper将Specflow绑定、步骤定义等注释视为隐式使用

Binding 如何让Resharper将Specflow绑定、步骤定义等注释视为隐式使用,binding,annotations,resharper,specflow,Binding,Annotations,Resharper,Specflow,我将重塑器与Specflow一起使用,ResharperCode检查将步骤定义、绑定和挂钩标记为从未使用过 我试着用我的答案 但无法成功获取正确的外部批注。以下是我在外部注释文件中尝试的内容:- <assembly name="TechTalk.SpecFlow.dll"> <member name="T:TechTalk.SpecFlow.BindingAttribute"> <attribute ctor="M:JetBrains.Annotatio

我将重塑器与Specflow一起使用,ResharperCode检查将步骤定义、绑定和挂钩标记为从未使用过

我试着用我的答案

但无法成功获取正确的外部批注。以下是我在外部注释文件中尝试的内容:-

<assembly name="TechTalk.SpecFlow.dll">
  <member name="T:TechTalk.SpecFlow.BindingAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.GivenAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
    <member name="T:TechTalk.SpecFlow.WhenAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.ThenAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
</assembly>
谁能告诉我在配置这个时我做错了什么吗

编辑完成的xml,该xml在遵循Alexander的帖子后运行良好:-

<!--Deploy to %ReSharperInstallDir%\Bin\ExternalAnnotations
    to check the ExternalAnnotations have worked, highlight one and press Ctrl-Shift-F1
    see https://stackoverflow.com/questions/23359738/how-can-i-get-resharper-to-treat-specflow-bindings-step-def-etc-annotations-as
    for additional info
-->
<assembly name="TechTalk.SpecFlow">
  <member name="T:TechTalk.SpecFlow.BindingAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.GivenAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.WhenAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.ThenAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.BeforeTestRunAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.AfterTestRunAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.BeforeFeatureAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.AfterFeatureAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.BeforeScenarioAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.AfterScenarioAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.BeforeAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.AfterAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.BeforeScenarioBlockAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.AfterScenarioBlockAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.BeforeStepAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.AfterStepAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.StepArgumentTransformationAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.StepDefinitionAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
  <member name="T:TechTalk.SpecFlow.ScopeAttribute">
    <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
  </member>
</assembly>  

看起来不错,但是自从ReSharper 8.2以来,外部注释被部署为ReSharper的扩展(在Extensions manager中),因此它们不再位于程序文件下

您可以做的,只是为了测试这是否有效,就是将文件命名为
TechTalk.SpecFlow.ExternalAnnotations.xml
,并将其放在DLL旁边(我假设您使用的是SpecFlow Nuget包,所以暂时将其放在lib中)。您需要重新加载解决方案。然后,您应该能够看到是否应用了属性。您还可以使用QuickDoc功能(通过在属性上按Ctrl-Q或Ctrl-Shift-F1)来确定是否应用了该属性,例如:

如果这样做行得通,那么您可以自己将注释作为一个组件分发

  • 将TechTalk.SpecFlow.xml放入C:\Program Files(x86)\JetBrains\ReSharper\v8.2\Bin\ExternalAnnotations\

  • 从您提到的xml中的
    中删除“.dll”扩展名以获得

  • 重新开放Visual Studio

  • 清理溶液的重新竖琴缓存


  • 谢谢你的建议,亚历山大。除第4点外,我已经尝试了以上所有方法-如何清除resharper缓存?谢谢,我回到办公桌后会尝试一下,按照Alex的建议清理缓存后效果很好。谢谢你给我的建议。所以我应该把XML放在nuget包中specflow dll的旁边?我是否需要在项目或解决方案中添加引用或显式包含该文件?另外,如果它是一个XML文件,为什么要将其重命名为.dll?哎呀,你说得对,我的意思是
    .XML
    !我编辑了答案,谢谢!我想让你把它放在nuget的DLL旁边,看看它是否有效。ReSharper通过使用
    DllName.ExternalAnnotations.xml
    约定,在外部注释(使用
    AssemblyName\anything.xml
    约定)或实际DLL旁边查找注释。如果它能工作,也就是说,ReSharper加载注释,并使您的方法显示为“已使用”,那么您知道它能工作,并且可以自己将注释放入一个包中分发给每个人。看看R#API文档的打包部分,它列出了外部注释的命名约定:关于quick doc的好提示!我使用的xml请参见下文-请随意在此基础上制作Nuget包!
    <!--Deploy to %ReSharperInstallDir%\Bin\ExternalAnnotations
        to check the ExternalAnnotations have worked, highlight one and press Ctrl-Shift-F1
        see https://stackoverflow.com/questions/23359738/how-can-i-get-resharper-to-treat-specflow-bindings-step-def-etc-annotations-as
        for additional info
    -->
    <assembly name="TechTalk.SpecFlow">
      <member name="T:TechTalk.SpecFlow.BindingAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.GivenAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.WhenAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.ThenAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.BeforeTestRunAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.AfterTestRunAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.BeforeFeatureAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.AfterFeatureAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.BeforeScenarioAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.AfterScenarioAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.BeforeAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.AfterAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.BeforeScenarioBlockAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.AfterScenarioBlockAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.BeforeStepAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.AfterStepAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.StepArgumentTransformationAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.StepDefinitionAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
      <member name="T:TechTalk.SpecFlow.ScopeAttribute">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
      </member>
    </assembly>