来自 Resource.Designer.cs 的模糊引用智能感知错误

Ambiguous reference intellisense error from Resource.Designer.cs

我 运行 在 Visual Studio 2017 年开发时遇到了一个奇怪的错误,我已经可以忽略一段时间了,但现在开始真正 错误我。

我将这个问题称为 bug 而不是 error 因为我仍然能够在 [=103] 中构建我的项目=] 并将它们部署到我的开发设备上,构建输出没有错误或警告。暂时忽略这似乎没问题,但随着时间的推移,它已成为一个问题,因为我的智能感知将其用红色下划线标记为错误

每次我从 Resource class 引用属性时。正如您可能猜到的那样,我经常引用这个 class 并且 Visual Studio 编辑器最终会被这些 "errors" 弄得乱七八糟,这 (a) 阻碍了我在代码中找到实际错误的能力,并且 (b ) 无缘无故地激怒了我...

"Error"调查

.

尝试过的解决方案

旁注

6/6/2018 Update

If you have ReSharper, you most likely will be able to disregard my per-project solution described below and, instead, simply install the latest version (currently ReSharper 2018.1.2). Apparently, the underlying issue was caused by a bug in a previous version. Upgrading resolved the issue for me.

See youtrack.jetbrains.com/issue/RSRP-469636 for more information.

Thanks to @davidbauduin over at Xamarin Forums for this information.


我相信我已经找到了潜在的问题并且有一个可行的解决方案。

解决方案

将以下内容添加到 .csproj 文件的 <PropertyGroup> 部分:

<AndroidUseManagedDesignTimeResourceGenerator>False</AndroidUseManagedDesignTimeResourceGenerator>

原因

虽然以前版本的 Visual Studio 默认关闭该功能,但最新的 VS2017 更新 (15.7.3) 已将其打开。该功能生成第二个 Resources.Designer.cs 文件,导致引用不明确问题。

您可以通过将鼠标悬停在出现 Intellisense 错误的资源常量上进行验证,右键单击,selecting "Go To Definition",然后 selecting 第一项,这会将您带到一个 Resource.Designer.cs 文件。如果您重复,但 select 第二个,您将被带到另一个 Resource.Designer.cs 文件。其中之一指向 obj\Debug\designtime\Resource.Designer.cs 文件。通过如上所述将该功能设置为 False,将不会生成 obj\Debug\designtime 路径中的 Resource.Designer.cs 文件。

关于 AndroidUseManagedDesignTimeResourceGenerator 功能的信息:

https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.1/#design-time-builds-managed-resource-parser

https://github.com/dotnet/project-system/blob/master/docs/design-time-builds.md#design-time-builds

希望对您有所帮助!