如何让Resharper将Specflow Bindings,Step Def等注释视为隐式使用

时间:2014-04-29 08:43:56

标签: binding annotations resharper specflow

我使用Reshaper和Specflow,ResharperCode Inspection正在标记步骤定义,绑定和挂钩从未使用过。

我尝试使用here

的答案

但无法成功获取正确选取的外部注释。这是我在External Annotations文件中尝试的内容: -

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

我尝试保存在C:\ Program Files(x86)\ JetBrains \ ReSharper \ v8.2 \ Bin和C:\ Program Files(x86)\ JetBrains \ ReSharper \ v8.2 \ Bin \ ExternalAnnotations(由于ExternalAnnotations文件夹在默认安装中不存在,因此不太清楚它应该去哪里)

但是当我关闭并重新打开VS时,检查仍然会选择Bindings并将步骤defs视为未使用: -

Solution qdf.AcceptanceTests.sln
Project Alpari.QualityAssurance.SpecFlowExtensions
  Alpari.QualityAssurance.SpecFlowExtensions\Steps\CrossStepDefinitionFileTwo.cs:7 Class 'CrossStepDefinitionFileTwo' is never used
  Alpari.QualityAssurance.SpecFlowExtensions\Steps\CrossStepDefinitionFileTwo.cs:10 Method 'GivenICreateAnInstanceOfStepDefinitionOneFromStepDefinitionTwo' is never used
  Alpari.QualityAssurance.SpecFlowExtensions\Steps\CrossStepDefinitionFileTwo.cs:42 Method 'GivenICallAMethodInStepDefinitionTwoThatCallsTheSameMethodInStepDefinitionFileOne' is never used

任何人都可以告诉我在配置中遇到了什么错误吗?

编辑完成了xml,在遵循亚历山大的帖子后工作正常: -

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

2 个答案:

答案 0 :(得分:7)

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

  2. 从您提到的xml中移除<assembly name="TechTalk.SpecFlow.dll">中的“.dll”扩展程序,以获取<assembly name="TechTalk.SpecFlow">;

  3. 重新打开Visual Studio;

  4. 清理ReSharper缓存以获得解决方案;

答案 1 :(得分:2)

看起来是正确的,但是自ReSharper 8.2起,外部注释被部署为ReSharper的扩展(在扩展管理器中),因此它们不再位于Program Files下。

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

如果这确实有效,您可以自己将注释分发为ReSharper extension