7

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>  
Community
  • 1
  • 1
Dave00Galloway
  • 609
  • 1
  • 6
  • 20

2 Answers2

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

Alexander Kurakin
  • 13,373
  • 2
  • 33
  • 29
2

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!

Community
  • 1
  • 1
Igal Tabachnik
  • 31,174
  • 15
  • 92
  • 157
  • Thanks for the advice there Igal. So I should put the XML next to the specflow dll inside the nuget package? Do I need to add a reference or explicitly include the file in my project or solution? Also, if it's an XML file, why rename it to .dll? – Dave00Galloway Apr 29 '14 at 09:50
  • Oops, you're right, I meant `.xml`! I edited the answer, thanks! I wanted you to place it next to the DLL in nuget just to see if it worked. ReSharper looks for annotations either in External Annotations (using a `AssemblyName\anything.xml` convention) or next to the actual DLL, by using `DllName.ExternalAnnotations.xml` convention. If it works, that is, ReSharper loads the annotations, and it makes your methods appear 'used', then you know it works, and can put the annotations in a package yourself to distribute to everyone. – Igal Tabachnik Apr 29 '14 at 09:56
  • Take a look at the Packaging section of the R# API docs, it lists the naming conventions for external annotations: http://confluence.jetbrains.com/display/NETCOM/1.06+Packaging+%28R8%29 – Igal Tabachnik Apr 29 '14 at 09:59
  • Nice tip about quick doc! see below for the xml I used - feel free to make a Nuget package based on this! – Dave00Galloway Apr 29 '14 at 12:41