简体   繁体   English

如何忽略NodaTime nuget包xml文档文件中对jetbrains.annotations.dll的引用

[英]How to ignore reference to jetbrains.annotations.dll in NodaTime nuget package xml documentation file

I lean quite heavily on Resharper context actions to generate boilerplate code. 我非常依赖Resharper上下文操作来生成样板代码。 The Check parameter for null context action had, up until recently, generated code that performs the null check and throws accordingly. 直到最近, 上下文操作的Check参数生成了执行空检查并相应抛出的代码。 However, now it is adding a Resharper specific [NotNull] annotation to the parameter as part of the method signature. 但是,现在它将Resharper特定的[NotNull]注释作为方法签名的一部分添加到参数中。

Looking at this related question Stop ReSharper from Adding Annotations , I've checked across my solution codebase for jetbrains.annotations.dll references but not found any. 看看这个相关问题Stop ReSharper from Adding Annotations ,我已经在我的解决方案代码库中查看了jetbrains.annotations.dll引用,但没有找到任何内容。

However, searching across all files I've found references to jetbrains.annotations.dll in the xml documentation file for NodaTime (NodaTime.xml). 然而,在所有文件中搜索,我发现引用jetbrains.annotations.dllNodaTime(NodaTime.xml)的XML文档文件。

Specifically, entries like this: <member name="T:JetBrains.Annotations.NotNullAttribute"> . 具体来说,这样的条目: <member name="T:JetBrains.Annotations.NotNullAttribute">

Im not categorically stating that this is the root cause. 我并非断然断言这是根本原因。 However, NodaTime is the most recent nuget package I have added since the issue began, and a grep across the solution shows this to be the single point of reference. 但是,NodaTime是我自问题开始以来添加的最新nuget包,并且解决方案中的grep显示这是单一参考点。

Should xml documentation files be including these references, and if so, is there a way for me to configure Resharper to ignore them? xml文档文件是否应该包含这些引用,如果是这样,有没有办法让我配置Resharper来忽略它们?

UPDATE I've decompiled the NodaTime assembly and although it doesn't have any binary references to jetbrains.annotations.dll it does appear to (re)declare the offending JetBrains.Annotations namespaces and annotations within itself. 更新我已经反编译了NodaTime程序集,虽然它没有对jetbrains.annotations.dll的任何二进制引用,但它确实(重新)声明了违规的JetBrains.Annotations名称空间和注释本身。

As per citizenmatts suggestion, Ive used the Resharper take me to definition tool for the [NotNull] attribute and this goes to the NodaTime.dll 根据citizenmatts建议,我使用Resharper 带我去 [NotNull]属性的定义工具,这将转到NodaTime.dll

I've also just noticed that the NotNull attributes Resharper is including do not compile and complain of Cannot reference internal class NotNullAttribute . 我还注意到Resharper的NotNull属性包括不编译和抱怨Cannot reference internal class NotNullAttribute Hence I obviously don't have the jetbrains.annotations.dll included anyway. 因此,我显然没有包含jetbrains.annotations.dll。

UPDATE 2 Just done the obvious thing of creating a new blank project in VS2013 and checking the null check context action in Resharper works. 更新2刚刚完成了在VS2013中创建一个新的空白项目并检查Resharper中的空检查上下文操作的明显事情。 Then added NodaTime nuget package and rechecked - and indeed it adds the [NotNull] attribute and the project wont compile. 然后添加了NodaTime nuget包并重新检查 - 实际上它添加了[NotNull]属性并且项目不会编译。

UPDATE 3 As suggested by Jon Skeet I've tried "turning off" data annotations using Resharper-->Code Inspection-->Code Annotations-->Unticking JetBrains.Annotations. 更新3正如Jon Skeet所建议的那样,我尝试使用Resharper - > Code Inspection - > Code Annotations - > Unticking JetBrains.Annotations“关闭”数据注释。 However, this has no affect and the NotNull attribute continues to be included. 但是,这没有任何影响,并且继续包含NotNull属性。

Looks like I may just have to return to System.DateTime. 看起来我可能只需要返回System.DateTime。

Noda Time deliberately ships with an internal copy of the R# annotations, so that those who do want them can benefit from them - it will know which methods are pure, etc. 野田佳彦时间故意船舶的R#标注的内部副本,让那些谁希望他们能够从中受益-它会知道哪些方法是纯粹的,等等。

It sounds like you don't actually want to use annotations at all, so it's just worth disabling them. 听起来你实际上根本不想使用注释,所以它只是值得禁用它们。 That's easy from the R# options - under Code Inspection / Code Annotations, uncheck the JetBrains.Annotations option. R#选项很简单 - 在Code Inspection / Code Annotations下,取消选中JetBrains.Annotations选项。

We can certainly consider moving the annotations into a specific namespace for Noda Time in the future, so that it's more opt-in than opt-out, but this is probably a good solution if you don't want to use annotations, as it makes it absolutely clear to R# that you really don't want to use them, even if other libraries include annotations. 我们当然可以考虑在未来将注释移动到Noda Time的特定命名空间中,这样它比选择退出更加选择,但如果您不想使用注释,这可能是一个很好的解决方案,因为它使这是绝对清楚的是,你真的不想使用它们,即使其他库包括注释R·。

EDIT: Just to promote Matt's comment into this answer: 编辑:只是为了促进马特对这个答案的评论:

Sadly, this is a bug in ReSharper - it doesn't take visibility of the NotNullAttribute into account before applying it. 遗憾的是,这是ReSharper中的一个错误 - 它在应用之前不会将NotNullAttribute可见性考虑在内。 Here's the ticket to track and vote on: http://youtrack.jetbrains.com/issue/RSRP-413425 这是跟踪和投票的门票:http: //youtrack.jetbrains.com/issue/RSRP-413425

NodaTime.dll ships with the JetBrains annotations compiled in as internal symbols, which means they're used internally to NodaTime and not visible for anyone else to use. NodaTime.dll附带作为内部符号编译的JetBrains注释,这意味着它们在内部用于NodaTime,而其他任何人都无法看到它们。 However, ReSharper can see these annotations that have been applied to the NodaTime classes and methods. 但是,ReSharper可以看到已应用于NodaTime类和方法的这些注释。

NodaTime doesn't have any binary references to JetBrains.Annotations.dll, and neither ReSharper nor Visual Studio should be adding a reference to a dll based on xml documentation. NodaTime没有对JetBrains.Annotations.dll的任何二进制引用,并且ReSharper和Visual Studio都不应该基于xml文档添加对dll的引用。 If ReSharper is able to add a [NotNull] annotation to your code, the dll must be being referenced from somewhere. 如果ReSharper能够在代码中添加[NotNull]注释,则必须从某处引用dll。 I'd suggest invoking ReSharper's "go to definition" on the [NotNull] and see where it takes you - it should show you where the annotations dll is being referenced from, and you should be able to remove it easily from there. 我建议在[NotNull]上调用ReSharper的“go to definition”并查看它的位置 - 它应该显示注释dll的引用位置,你应该可以从那里轻松删除它。

Update: As noted above, and in the other answers, the issue is a bug in ReSharper that doesn't check the accessibility of the attribute before applying it. 更新:如上所述,在其他答案中,问题是ReSharper中的一个错误,它在应用属性之前不会检查属性的可访问性。 Here's the YouTrack ticket to track and vote on: http://youtrack.jetbrains.com/issue/RSRP-413425 这里的YouTrack票跟踪和投票: http://youtrack.jetbrains.com/issue/RSRP-413425

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM