JetBrains.Annotations not working from referenced NuGet package

Answered

Hello,

Please forgive me if there is already a topic for this issue but I couldn't find it.

We use the Jetbrains.Annotations package in our projects, including our company base package.
Our problem is that if we consume this package in on of our projects the PathReferenceAttribute isn't working.

So for instance, we have this method:
Snippet

public static string Static(this UrlHelper helper, [PathReference] string contentPath)

And we consume it like this:

Snippet

<script type="text/javascript" src="@Url.Static( "~/Scripts/jQuery/jquery-1.11.0.min.js" )"> </script>

 

I would then expect it to have path auto complete, but sadly it doesn't.

When using the PathReference within a project in the same Solutions everything works as expected and we get auto complete etc.
We are referencing the JetBrains.Annotations package in both projects (its a dependency in our base library) so afaik everything should be fine.

Is there something we are missing?

 

7 comments
Comment actions Permalink

Have you defined the JETBRAINS_ANNOTATIONS conditional compilation symbol, as described in the documentation?

Annotations in Source Code
By default, all annotation attribute classes are marked with [Conditional("JETBRAINS_ANNOTATIONS")] so the compiler will ignore the attribute usages in your code, which means that no binary reference to the 'JetBrains.Annotations.dll' assembly will be produced.

0
Comment actions Permalink

Hi Richard,

No I haven't because the documentation says that isn't needed if you include/reference the .dll

Where would one need to define that symbol?

0
Comment actions Permalink

You'd need to define it in the "base package" project's properties.

If you don't define the symbol, the annotations will only work within the same solution. The attributes will not be included in the compiled output, and will therefore have no effect when you reference the assembly from a different solution.

The other option would be to use external annotations, but they're much more complicated to create.

0
Comment actions Permalink

Do I need to create a property in the .csproj? And so how do I need to define it?

If not where and how do I define it?

Sadly this is not documented and my Google-fu doesn't seem strong enough. :(

0
Comment actions Permalink

It's in the project properties, on the "Build" page:
Conditionally Compiling Code Based on Symbols

1
Comment actions Permalink

Thanks, that was it!

Might be a good idea to document this better btw.

Thanks for the help :)
Topic may be closed (if that's possible).

 

0
Comment actions Permalink

Just a note to self and others.

You must add the attribute to the Release Configuration, adding it to the Debug Configuration doesn't work.

0

Please sign in to leave a comment.