我尝试使用 Visual Studio Developer 命令提示符在 Windows 中创建 Maui 项目
:
dotnet new maui
但它没有创建毛伊岛项目,收到错误消息没有找到匹配的模板:毛伊岛
我在我的机器上安装了.Net 5和Visual Studio 2019。
我的系统中安装了Windows 10 20H2版本。以及 Visual Studio Professional 2019 和 Visual Studio Professional 2019 预览版。点击以下链接进行 MAUI 设置。
https://learn.microsoft.com/en-us/dotnet/maui/get-started/installation。
我已经安装了.Net MAUI Preview 5。并确保了maui-check。一切看起来都很棒。
但是,当我在 MAUI 中创建新项目并尝试构建时,显示以下错误。
错误 NETSDK1112:未下载 Microsoft.iOS.Runtime.iossimulator-x64 的运行时包。尝试使用 RuntimeIdentifier“iossimulator-x64”运行 NuGet 恢复。1>完成构建项目“MauiApp5.csproj”——失败。
错误 NETSDK1112:未下载 Microsoft.MacCatalyst.Runtime.maccatalyst-x64 的运行时包。尝试使用 RuntimeIdentifier“maccatalyst-x64”运行 NuGet 恢复。1>完成构建项目“MauiApp5.csproj”——失败。
我已经多次修复 Visual Studio 并清理 nuget 缓存。我不知道出了什么问题。
并显示以下警告。
警告 MSB3779 所引用的 SDK“Microsoft.VCLibs.Desktop,版本 = 14.0”不支持正在构建的项目“任何 CPU”的处理器架构。请考虑将项目的目标处理器架构(在 Visual Studio 中,这可以通过配置管理器完成)更改为 SDK 支持的架构之一:“x86、x64、ARM、ARM64”。MauiApp5.WinUI C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2472
我尝试解决这些问题,但没有运气。
我正在尝试 MAUI,但遇到了一个奇怪的错误。它不会让我添加新页面,每次我尝试这样做时,InitializeComponent构造函数中都会出现错误:
当前上下文中不存在名称“InitializeComponent”
Microsoft.Maui.Controls我已在 C# 代码和 XAML 代码中添加。
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Run Code Online (Sandbox Code Playgroud)
有人知道在这里可以做什么吗?
最近,我收到了在 .NET MAUI 中的 shell 应用程序和网页之间创建双向互操作桥的任务。没有找到任何方法来解决这个问题,我首先想到在 Xamarin.Forms 中创建它,因为 MAUI 是它的延续。
创建此应用程序后,我尝试使用 dotnet/maui github wiki 上的 Microsoft 说明将其转换为 MAUI。
我现在遇到的主要问题是我一直在 Android 的WebViewRenderer、WebViewClient和Java.Lang.Object上使用扩展,以便能够向 WebView 发送和接收 javascript。
public class ExtendedWebViewRenderer : WebViewRenderer
{
private const String JavascriptFunction = "function invokeCSharpAction(data){jsBridge.invokeAction(data);}";
public ExtendedWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
Control.RemoveJavascriptInterface("jsBridge");
((ExtendedWebView)Element).Cleanup();
}
if (e.NewElement != null)
{
Control.SetWebViewClient(new JavascriptWebViewClient($"javascript: {JavascriptFunction}"));
Control.AddJavascriptInterface(new JsBridge(this), "jsBridge");
}
}
}
public …Run Code Online (Sandbox Code Playgroud) 我根据入门指南创建了 MAUI 项目:
这是一个默认项目,没有任何更改。现在,我正在尝试构建我的项目,但出现以下错误:
Specified AndroidManifest file does not exist: C:\***\source\repos\MauiApp\MauiApp\AndroidManifest.xml.Assets file 'C:\***\source\repos\MauiApp\MauiApp\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.我尝试恢复 NuGet 但没有帮助。我错过了什么?或任何修复建议?
编辑:
出于测试目的,我想“捕获”我的应用程序中发生的任何错误并将其显示在页面上(而不是在控制台中)。为此,我在 .Net 6 框架中发现了ErrorBoundary组件。
来自 Microsoft 的 ErrorBoundaries 文档
起初,我在Bazor WebAssembly项目中成功测试了这个组件。
脚步:
自定义错误边界
@inherits ErrorBoundary
@if (CurrentException is null)
{
@ChildContent
}
else if (ErrorContent is not null)
{
@ErrorContent(CurrentException)
}
else
{
<div style="background-color: yellow; border: 2px dashed black; white-space: pre; font-family: consolas, monospace;">
@foreach (var exception in receivedExceptions)
{
<div class="received-exception" style="background-color: rgba(255,255,255,0.3); margin: 0.5rem; padding: 0.5rem;">
@exception.Message …Run Code Online (Sandbox Code Playgroud) 在登录流程中,登录页面通常没有构成应用程序主要流程的底部选项卡。
AppShell.xaml
<TabBar>
<ShellContent Title="Home"
Icon="home.png"
ContentTemplate="{DataTemplate local:HomePage}"/>
<ShellContent Title="Articles"
Icon="articles.png"
ContentTemplate="{DataTemplate local:ArticlesPage}" />
</TabBar>
Run Code Online (Sandbox Code Playgroud)
因此,如果登录成功,我尝试从登录页面导航到作为 Shell 中 TabBar 的一部分的主页。问题是 Shell 然后导航到主页,就好像它是一个独立的页面,没有 TabBar。我假设答案在于导航到 TabBar 部分本身,我不知道。
我们是否在 .NET MAUI 应用程序中创建/使用 an HttpClient,就像在 Web 或 API 应用程序中一样?具体来说,我将我的HttpClient' 添加到我的应用程序中Program.cs使用IHttpFactory-- 见下文:
builder.Services.AddHttpClient("NamedClient1", config =>
{
var url = currentState == "production"
? "https://my-production-url"
: "https://sandbox-url";
config.BaseAddress = new Uri(url);
});
Run Code Online (Sandbox Code Playgroud)
我理解 .NET MAUI 的想法是标准化我们处理事物的方式。当我尝试在 .NET MAUI 应用程序中添加该行时builder.Services,IntelliSense 并不建议AddHttpClient。
我正在尝试将我的 Xamarin 项目迁移到毛伊岛,但我一直在寻找与毛伊岛项目上的 Android.App.Application.Context 等效的命名空间。DatabaseHelper 类具有以下路径:MyProject -> Platforms -> Android -> Helpers。
有谁知道毛伊岛 Android.App.Application.Context 的等效命名空间是什么?
CS0234:命名空间“AAT.Platforms.Android”中不存在类型或命名空间名称“App”(您是否缺少程序集引用?)
谢谢!
maui ×10
c# ×4
xamarin ×4
.net ×2
.net-maui ×2
android ×2
.net-6.0 ×1
asp.net-core ×1
blazor ×1
javascript ×1
maui-blazor ×1
webview ×1
windows ×1