来自Resource.Designer.cs的含糊的参考智能提示错误 [英] Ambiguous reference intellisense error from Resource.Designer.cs

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

问题描述

在Visual Studio 2017上进行开发时,我遇到了一个特有的错误,我可以忽略一会儿,但是现在开始真正成为 bug 了.

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.

我将此问题称为 bug 而不是 error ,因为我仍然能够在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

我每次都引用资源类中的属性.您可能会猜到,我经常引用该类,而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...

  • 如上图所示,Intellisense正在为 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>Resources\Resource.Designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.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文件的<PropertyGroup>部分中添加以下内容:

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错误的资源常量上,右键单击,选择转到定义",然后选择第一个项目,该项目将带您到Resource.Designer.cs文件.如果重复,但选择第二个,则将转到另一个Resource.Designer.cs文件.其中之一指向obj \ Debug \ designtime \ Resource.Designer.cs文件.如上所述,通过将该功能设置为False,将不会生成obj \ Debug \ designtime路径中的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 obj\Debug\designtime\Resource.Designer.cs file. By setting that feature to False as described above, that Resource.Designer.cs file in the obj\Debug\designtime 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天全站免登陆