来自 Resource.Designer.cs 的模糊参考智能感知错误 [英] Ambiguous reference intellisense error from Resource.Designer.cs

查看:24
本文介绍了来自 Resource.Designer.cs 的模糊参考智能感知错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2017 上开发时遇到了一个奇怪的错误,我已经能够忽略一段时间了,但现在开始真正错误我.

I am running into a peculiar bug when developing on Visual Studio 2017 that I have been able to ignore for a while, but is now beginning to really bug me.

我将此问题称为错误而不是错误,因为我仍然能够在 Visual Studio 中构建我的项目并将它们部署到我的开发设备而不会出错或来自构建输出的警告.忽略这一点似乎没问题,但随着时间的推移,它已成为一个问题,因为我的智能感知将其用红色下划线作为错误

I refer to this issue as a bug rather than an error because I am still able to build my projects in Visual Studio and deploy them to my development device without errors or warnings from the build output. This might seem alright to ignore for a bit, but over time it has become an issue because my intellisense is underlining it in red as an error

每次我从 Resource 类中引用属性时.正如您可能猜到的那样,我经常引用这个类,而 Visual Studio 编辑器最终会因这些错误"而变得杂乱无章,这 (a) 妨碍了我在代码中找到实际错误的能力,并且 (b) 无缘无故地激怒我......

every time I reference attributes from the Resource class. As you might guess, I refer this class a lot and the Visual Studio editor eventually becomes cluttered with these "errors" which (a) hinders my ability to find actual errors in my code and (b) irritates me beyond all reason...

  • 如上图所示,智能感知正在为 Resource 类中的每个属性选择一个模糊引用".当我检查我的 Resource.Designer.cs 文件时,我只看到一个参考,但出现第二个错误
  • As shown in the last image, intellisense is picking up an "Ambiguous Reference" to each attribute in the Resource class. When I check my Resource.Designer.cs file I only see one reference, but get a second error

.

  • 现在告诉我已声明同名成员".这让我相信还有第二个 Resource.Designer.cs 文件,但我的解决方案资源管理器和 Windows 资源管理器都只显示一个.
  • It is now telling me that that a "Member with the same name is already declared". This lead me to believe that there is a second Resource.Designer.cs file, but my solution explorer and windows explorer both show only one.

  • 将命名空间从 InventoryApp(文件的默认命名空间)更改为 InventoryApp.Resources.这让我摆脱了可怕的错误,但是,在构建项目时,它会将文件中的命名空间恢复为默认值,并且错误会再次弹出.一个更了解的人还告诉我,这是一个很大的禁忌.
  • 删除Resource.Designer.cs文件,从项目中删除obj"和bin"文件夹,清理并重建解决方案,然后添加新的Resource.Designer.cs 文件返回到我的解决方案.这并没有解决问题.
  • 从头开始创建一个全新的项目.即使从 Visual Studio 模板创建空白 Android 应用程序后,错误仍然存​​在.这就引出了一个问题:这是我安装的 Xamarin.Android 的问题吗?
  • Changed the namespace from InventoryApp (the default namespace of the file) to InventoryApp.Resources. This rid me of the ghastly errors but, upon building the project, it reverts the namespace in the file back to it's default, and the errors pop back up. I was also told by somebody who knows better that this is a big no-no.
  • Deleted the Resource.Designer.cs file, deleted the "obj" and "bin" folders from the project, cleaned and rebuilt the solution, then added the new Resource.Designer.cs file back to my solution. This did nothing to solve the problem.
  • Created an entirely new project from scratch. Even after creating a Blank Android App from the Visual Studio templates, the error persists. This begs the question: Is this a problem with my installation of Xamarin.Android?
  • Resource.Designer.cs 文件的构建操作设置为编译"
  • .csproj 配置文件包含以下标签:

  • The Resource.Designer.cs file's Build Action is set to "Compile"
  • The .csproj config file contains the tags:

<AndroidResgenFile>ResourcesResource.Designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
<AndroidManifest>PropertiesAndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>

推荐答案

6/6/2018 更新

如果您有 ReSharper,您很可能可以忽略我下面描述的每个项目的解决方案,而只需安装最新版本(当前为 ReSharper 2018.1.2).显然,根本问题是由先前版本中的错误引起的.升级为我解决了这个问题.

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.

有关详细信息,请参阅 youtrack.jetbrains.com/issue/RSRP-469636.

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

感谢 Xamarin 论坛上的 @davidbauduin 提供此信息.

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

<小时>

我相信我已经找到了根本问题并且有一个可行的解决方案.


I believe I have figured out the underlying issue and have a viable solution.

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

Add the following to the <PropertyGroup> section in your .csproj file:

<AndroidUseManagedDesignTimeResourceGenerator>False</AndroidUseManagedDesignTimeResourceGenerator>

原因

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

Reason

While previous versions of Visual Studio had that feature turned off by default, the latest VS2017 update (15.7.3) has it turned on. That feature generates a second Resources.Designer.cs file that results in the ambiguous reference issue.

您可以通过将鼠标悬停在包含 Intellisense 错误的资源常量上,右键单击,选择转到定义",然后选择第 1 项来进行验证,这会将您带到 Resource.Designer.cs 文件.如果您重复,但选择第二个,您将被带到不同的 Resource.Designer.cs 文件.其中之一指向 objDebugdesigntimeResource.Designer.cs 文件.通过如上所述将该功能设置为 False,将不会生成 objDebugdesigntime 路径中的 Resource.Designer.cs 文件.

You can verify by hovering over the resource constant with the Intellisense error, right-clicking, selecting "Go To Definition", and selecting the 1st item, which takes you to a Resource.Designer.cs file. If you repeat, but select the 2nd one, you'll be taken to a different Resource.Designer.cs file. One of these points to the objDebugdesigntimeResource.Designer.cs file. By setting that feature to False as described above, that Resource.Designer.cs file in the objDebugdesigntime path will not be generated.

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

希望这有帮助!

这篇关于来自 Resource.Designer.cs 的模糊参考智能感知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆