MAUI班级库可以编译Android(NO Android Nameapace)

发布于 2025-01-24 04:39:45 字数 205 浏览 0 评论 0原文

我正在尝试创建一个具有平台依赖部分的毛伊族类库。 在“ Android”类库的平台部分中,我为Android添加了代码,但是当我编译时,它告诉我它找不到Android名称空间。我已经根据编译Android的主程序检查Nuget软件包,并且相同。我已经卸载了主项目和类库,并相互检查项目代码,并且几乎相同。我能在编译Android的主要项目之间找到的唯一区别是,类库具有额外的Net6.0依赖关系。

I'm trying to create a Maui class library that has platform dependent sections.
In the class library's platform section for Android I've added code for Android, but when I compile it tells me that it can't find the Android namespace. I've check the Nuget packages against the main program that does compile Android and there the same. I've unloaded both the main project and the class library and check the project code against each other and there almost identical. The only difference that I can find between the main project that does compile Android is that the class library has an extra net6.0 dependency.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潇烟暮雨 2025-01-31 04:39:46

我在vs 2022 Preview 3中创建了一个“ .NET MAUI类库(预览)”。的确,有些问题 - 尤其是Intellisense。我找不到抑制某些IntelliSense错误的方法,但是我确实成功地构建了它。

注意:我确认大多数问题不会干扰构建项目。确实,这个问题只有在智能上才有可能。我并没有严格确定构建是否总是有效的。

1)可选:.csproj中,从< targetFrameworks>开始删除.net6.0;。但是不要删除,如果您正在制作不包含平台特定代码的库。
说明:这只会影响智能;可以在不这样做的情况下构建。
通常,这是在.NET6类库中想要的,但是直到VS Intellisense正确处理毛伊族类库,其特定于平台的代码往往会引起额外的IntelliSense投诉。如果您对所有特定于平台的文件进行(4),则可以将.NET6.0; in放置,而无需额外的IntelliSense错误。

2)上面的任何源文件,都是一个下拉列表,上面显示yourlibname(net6.0-xxx)。处理Android代码时,请选择YourLibName(Net6.0 Android)
说明:这只会影响智能;可以在不这样做的情况下构建。

3)在您的代码中,使用global :: android而不是android
说明:Intellisense似乎对其所在的上下文感到困惑。global ::确保它正在寻找“顶级”名称空间。

4)在类库中,IntelliSense不识别平台文件夹 - 将所有代码包装在适当的中。
说明:这只会影响智能;可以在不这样做的情况下构建。
这删除了在多个平台中定义不同的类别的错误;例如类PlatformClass1

5) 使用android;,使用android.app ,等Intellisense抱怨。

I've created a ".NET MAUI Class Library (Preview)" in VS 2022 Preview 3. Indeed, something is wrong - especially with Intellisense. I did not find a way to suppress certain Intellisense errors, but I did succeed in getting it to build.

NOTE: I confirmed that most of the issues do not interfere with Building the project. Indeed, its possible that the problem is ONLY with Intellisense; I didn't rigorously determine whether Build always worked.

1) OPTIONAL: In .csproj, REMOVE .net6.0; from start of <TargetFrameworks>. BUT DON'T remove, if you are making a library that doesn't contain platform-specific code.
EXPLANATION: This only affects Intellisense; can Build without doing this.
Normally this is wanted in a .net6 class library, but until VS Intellisense correctly handles Maui Class Libraries, with their platform-specific code, this tends to cause extra Intellisense complaints. If you do (4) for all platform-specific files, you can probably leave .net6.0; in, without extra Intellisense errors.

2) Above any source file, is a dropdown that says YourLibName (net6.0-xxx). When working on Android code, pick YourLibName (net6.0-android).
EXPLANATION: This only affects Intellisense; can Build without doing this.

3) In your code, use global::Android instead of Android.
EXPLANATION: Intellisense seems to be confused about the context it is in. global:: ensures that it is looking for a "top-level" namespace.

4) In a class library, Intellisense isn't recognizing platform folders - wrap all code in appropriate #if ANDROID, #if IOS, etc.
EXPLANATION: This only affects Intellisense; can Build without doing this.
This removes errors for a class that is defined differently in multiple platforms; e.g class PlatformClass1.

5) using Android;, using Android.App, etc - do work (in platform-specific folder) when "Build" - even if Intellisense complains.

差↓一点笑了 2025-01-31 04:39:46

我遇到了同样的问题 - 我决心不相信 @Toolmakersteve的回应,但恐怕他是正确的。 Especially #4 of his post about wrapping all platform specific content with

#if ANDROID
#endif

Also add it to your interfaces that reference platform specific namespaces.

这是有关以下内容的Microsoft页面的链接:
nofollow noreferrer”>

I had the same problem -- I was determined not to believe @ToolmakerSteve's response but I'm afraid he's correct. Especially #4 of his post about wrapping all platform specific content with

#if ANDROID
#endif

Also add it to your interfaces that reference platform specific namespaces.

Here's a link to a Microsoft page regarding this:
invoke platform specific code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文