找不到 Xamarin Android 资源文件 [英] Xamarin Android Resource file not found

查看:47
本文介绍了找不到 Xamarin Android 资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Visual Studio 中构建一个 Android 应用程序.当我尝试构建引用 Resources 文件夹中项目的应用程序时,我遇到了两个错误之一.

I am building an Android App in Visual Studio. When I try to build the app referencing items in the Resources folder, I get one of two errors.

如果我在Resource.Layout.[Id]"或Resource.Id.[Id]"前面加上我的项目的命名空间,我会收到这个错误:

If I preface "Resource.Layout.[Id]" or "Resource.Id.[Id]" with the namespace for my project, I get this error:

命名空间[app namespace]"中不存在类型或命名空间名称Resource"(您是否缺少程序集引用?)

The type or namespace name 'Resource' does not exist in the namespace '[app namespace]' (are you missing an assembly reference?)

如果我没有在对 Resource 的调用之前使用我的命名空间,它会尝试访问默认的 Android.Resource 类,但我收到此错误:

If I don't preface the call to Resource with my namespace, it tries to access the default Android.Resource class and I get this error:

Android.Resource.Layout"不包含[axml 文件]"的定义

'Android.Resource.Layout' does not contain a definition for '[axml file]'

有没有人遇到过这个错误?我已经搜索了一段时间,但找不到任何似乎有问题的东西.Resource.Designer 文件存在.我已经删除它并让它重新生成.Id 在 Resource 文件中,项目根本无法识别资源类.

Has anyone run across this error before? I've been searching for a while and cannot come up with anything that seems to be wrong. The Resource.Designer file exists. I've deleted it and let it get regenerated. The Ids are in the Resource file, the project just doesn't recognize that the resource class is there at all.

最初,此应用程序的命名空间以Android"结尾.考虑到这可能是问题的一部分,我已将其更改为_Android"和AndroidApp",包括更改项目属性中的默认命名空间以及更改每个文件中的命名空间声明.但是,每次更改后都会出现此错误.

Originally, the namespace for this application ended in "Android". Thinking that may be part of the issue, I've changed it to "_Android" and "AndroidApp", including changing the default namespace in the project properties and changing the namespace declaration in each file. However, this error persists through each change.

推荐答案

当您添加新文件并且 Visual Studio 将其设置为错误的构建操作时,可能会发生这种情况.我知道这已经发生了很多次,并且可能会花费很长时间试图弄清楚发生了什么.如果您右键单击该文件并看到构建操作.这应该设置为Android Resource.希望有帮助

This might happen when you add a new file and Visual studio sets it to the wrong build Action. I know this has happened me multiple times and can spend ages trying to figure out what going on. If you right click the file and see the Build action. this should be set to Android Resource. Hope it helps

这篇关于找不到 Xamarin Android 资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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