Question

I'm using Reshaper with Specflow, and the ResharperCode Inspection is flagging Step Definitions, Bindings and Hooks as never used.

I tried to use the answer from here

but wasn't able to successfully get the External Annotations to be picked up correctly. Here's what I tried in the External Annotations file:-

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

which I've tried saving in C:\Program Files (x86)\JetBrains\ReSharper\v8.2\Bin and C:\Program Files (x86)\JetBrains\ReSharper\v8.2\Bin\ExternalAnnotations (wasn't too clear where it should go since the ExternalAnnotations folder didn't exist in the default install)

but when I close and reopen VS, the Inspection still picks up the Bindings and step defs as unused:-

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

Can anyone tell me what I've done wrong in configuring this please?

EDIT completed xml which worked fine after following Alexander's post:-

<!--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>  
Was it helpful?

Solution

  1. Put your TechTalk.SpecFlow.xml to C:\Program Files (x86)\JetBrains\ReSharper\v8.2\Bin\ExternalAnnotations\;

  2. Remove ".dll" extension from <assembly name="TechTalk.SpecFlow.dll"> in xml you mentioned to get <assembly name="TechTalk.SpecFlow">;

  3. Reopen Visual Studio;

  4. Clean ReSharper caches for the solution;

OTHER TIPS

Looks about right, however since ReSharper 8.2, the External Annotations are deployed as an Extension for ReSharper (in Extensions manager), so they are not under Program Files any more.

What you could do, just to test if this works, is to name the file TechTalk.SpecFlow.ExternalAnnotations.xml, and place it next to your DLL (I assume you're using the SpecFlow Nuget package, so temporary put it there, in lib). You need to reload your solution. Then, you should be able to see whether the attributes were applied or not. You can also use the QuickDoc feature, (by pressing Ctrl-Q or Ctrl-Shift-F1 on the attribute) to determine if the attribute is applied, e.g.:

If this does work, you can then distribute the annotations as a ReSharper extension yourself!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top