10

I have created a XML annotation file for one of my libraries and want to make it available for all my projects without needing to copy it in each project binary folder.

For what I have read this can be done by copying it into the Resharper installation folder but I have tried a few places without success.

I have copied it in the following folders:

C:\Users\myuser\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\ExternalAnnotations\MyCompany

C:\Users\myuser\AppData\Local\JetBrains\ReSharper\vAny\vs14.0\Bin\ExternalAnnotations

The xml file has the exact same name as the dll that annotates, but xml extension. And the contents are like the follow:

<assembly name="Company.Tools.Libs.Logging">
  <member name="M:Company.Tools.Libs.Logging.Interfaces.IBasicLogger.WriteDebug(System.String,System.Object[])">
    <attribute ctor="M:JetBrains.Annotations.StringFormatMethodAttribute.#ctor(System.String)" />
    <argument>"format"</argument>
  </member>
  <member name="M:Company.Tools.Libs.Logging.Interfaces.IBasicLogger.WriteInfo(System.String,System.Object[])">
    <attribute ctor="M:JetBrains.Annotations.StringFormatMethodAttribute.#ctor(System.String)" />
    <argument>"format"</argument>
  </member>
  <member name="M:Company.Tools.Libs.Logging.Interfaces.IBasicLogger.WriteWarning(System.String,System.Object[])">
    <attribute ctor="M:JetBrains.Annotations.StringFormatMethodAttribute.#ctor(System.String)" />
    <argument>"format"</argument>
  </member>
  <member name="M:Company.Tools.Libs.Logging.Interfaces.IBasicLogger.WriteError(System.String,System.Object[])">
    <attribute ctor="M:JetBrains.Annotations.StringFormatMethodAttribute.#ctor(System.String)" />
    <argument>"format"</argument>
  </member>
  <member name="M:Company.Tools.Libs.Logging.Interfaces.IBasicLogger.WriteFatal(System.String,System.Object[])">
    <attribute ctor="M:JetBrains.Annotations.StringFormatMethodAttribute.#ctor(System.String)" />
    <argument>"format"</argument>
  </member>
</assembly>

What am I missing here?

UPDATE:

As @citizenmatt has said my xml was wrong, and the argument nodes need to be nested inside the attribute element. Doing this with a simple project I used to replicate the issue make it work, but that was by creating the external annotations in the same folder as the dll and with .ExternalAnnotation prefix.

I am still trying to find out where to copy it on my machine so its picked by Resharper without distributing it along the dll.

UPDATE 2:

After discussing with @citizenmatt I have decided to ship my annotations along the dll. He had a good point, adding it on the installation dir of Resharper will make them disappear in every new installation plus its not a very intuitive place. Also, I haven't been able to get VS to get my annotations from there.

Juan
  • 3,675
  • 20
  • 34

1 Answers1

3

If I remember correctly, I think it needs to be in a sub-folder of ExternalAnnotations. You'll also need to close and reopen your solution before it will be picked up.

You can also ship the file next to the .dll, as long as it ends with .ExternalAnnotations.xml, e.g. foo.dll would need foo.ExternalAnnotations.dll.

Alternatively, you can ship the annotations in an extension. This is packaged up as a nuget package with a custom file layout. You can see the community extensions project for an example of the nuspec file (if your assembly is a public assembly, you might even want to add a pull request!)

However, the example XML you've shown here is incorrect - the argument element needs to be a child of the attribute element. It's telling ReSharper how to build an argument that should be applied - the ctor attribute gives ReSharper the constructor (and the class), and then we need to pass arguments to that constructor - so each argument element needs to be a child of the attribute element. In other words:

<member name="M:Company.Tools.Libs.Logging.Interfaces.IBasicLogger.WriteDebug(System.String,System.Object[])">
<attribute ctor="M:JetBrains.Annotations.StringFormatMethodAttribute.#ctor(System.String)">
  <argument>format</argument>
</attribute>

citizenmatt
  • 18,085
  • 5
  • 55
  • 60
  • Tried on "C:\Users\myUser\AppData\Local\JetBrains\ReSharper\vAny\vs14.0\Bin\ExternalAnnotations\Company" without success (closing and opening VS afterwards). The extension options is interesting but I would like to just copy the file to a shared folder and got picked up by all solutions. – Juan Nov 02 '15 at 11:09
  • Have you had this xml working when it's side-by-side with the dll? You might want to try doing that, and have a look at the argument - I think you want it so that it's NOT quoted, so `format`. – citizenmatt Nov 02 '15 at 11:12
  • Not even copying in the same folder my project references the dll from seems to work. I renamed it to: "Company.Tools.Libs.Logging.ExternalAnnotations.xml" while the dll is called: "Company.Tools.Libs.Logging.dll". The quotes on the parameter were generated by ReSharper internal tools (http://hadihariri.com/2009/06/26/resharpers-hidden-gem/) which I use to generate the annotation file – Juan Nov 02 '15 at 16:32
  • Did you reopen your solution after copying it in? If you can send me the assembly and xml, I'll take a look (matt.ellis at jet brains - happy to sign NDAs). But on the face of it, everything looks ok, and it should work. – citizenmatt Nov 03 '15 at 17:32
  • Thanks @citizenmatt. I cannot send you the actual assembly but I will try to create a new similar one and send that to you. Quite busy at work lately so it could take me a while though – Juan Nov 04 '15 at 10:36
  • Cool. Some other thoughts - the first parameter of these methods is called `format`, isn't it? And this will only work when calling the methods directly via `IBasicLogger`. It won't work if you call it through a concrete class (I think, 95% sure of that). – citizenmatt Nov 06 '15 at 09:31
  • Oh, I think that could be then! I use a different interface that inherits from that one, I would try to add the annotation to the one I am actually using and let you know. Can you add that on the answer just in case it is the right thing? :) – Juan Nov 09 '15 at 11:18
  • Honestly, couldn't see the wood for the trees with this one - the XML was wrong! Sorry I didn't spot it sooner. I've updated the answer to show what it should be like. – citizenmatt Nov 10 '15 at 11:57