【问题标题】:How to build MAUI app to start on Windows如何构建 MAUI 应用程序以在 Windows 上启动
【发布时间】:2021-08-18 06:29:12
【问题描述】:

我在带有 .NET 6.0.100-preview.7.21379.14 的 Windows 10 上使用 MSVS 2022 preview 3.1,我能够创建 MAUI 应用程序并将其部署到 Android 模拟器中。

我想在我的 Windows 上运行它,因为 Android 模拟器非常慢,而且我对桌面更感兴趣。目前这可能吗?我尝试构建 WinUI 项目,它在磁盘上创建了一个可执行文件,但是当启动该可执行文件时,什么也没有发生。

我尝试使用 Publish to Folder 来获得相同的结果。我尝试再次使用 Deploy,但结果相同。这两个过程都没有错误,只是在磁盘上创建的可执行文件什么都不做。

应用是使用dotnet new maui -n HelloMauiPreview 命令创建的。

编辑: 我已将登录 obj\Release\net6.0-windows10.0.19041\win10-x64\Platforms\Windows\App.g.i.cs 文件放入 Main,如下所示:

        static void Main(string[] args)
        {
            global::WinRT.ComWrappersSupport.InitializeComWrappers();
            global::Microsoft.UI.Xaml.Application.Start((p) => {
            ...

第一行执行没有问题,程序卡在第二行的某个地方。有一个没有被调用的代表。所以它卡在Start 的开始和调用该委托之间的某个地方。没有其他内容被执行,因此global::Microsoft.UI.Xaml.Application.Start 行之后的行不会被执行。

此外,当我说“卡住”时,应用程序不会挂在那里,它会以某种方式终止。使用事件查看器我发现了以下事件:

Description: The process was terminated due to an unhandled exception.
Exception Info: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Runtime.InteropServices.COMException (0x80040154): Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
   at WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName) in Microsoft.WinUI.dll:token 0x6000023+0x6e
   at Microsoft.UI.Xaml.Application._IApplicationStatics..ctor() in Microsoft.WinUI.dll:token 0x601388f+0x1c
   at System.RuntimeType.CreateInstanceOfT() in System.Private.CoreLib.dll:token 0x60006c8+0x3e
   --- End of inner exception stack trace ---
   at System.RuntimeType.CreateInstanceOfT() in System.Private.CoreLib.dll:token 0x60006c8+0x4e
   at System.Activator.CreateInstance[T]() in System.Private.CoreLib.dll:token 0x60009ed+0x0
   at WinRT.WeakLazy`1.get_Value() in Microsoft.WinUI.dll:token 0x6000019+0x20
   at Microsoft.UI.Xaml.Application._IApplicationStatics.get_Instance() in Microsoft.WinUI.dll:token 0x6013890+0x0
   at Microsoft.UI.Xaml.Application.Start(ApplicationInitializationCallback callback) in Microsoft.WinUI.dll:token 0x6009288+0x0

编辑 2: 这个问题似乎与https://github.com/dotnet/maui/issues/1557

相似/相同

【问题讨论】:

    标签: .net windows maui


    【解决方案1】:

    您必须设置WindowsMachine 目标和适当的框架。 然后按F5运行并在Windows的设置应用程序中启用Install from unknown sources或类似的,对我来说它会自动弹出(我在Win11上)

    然后,您可以使用调试工具运行应用程序:

    【讨论】:

    • 我会接受你的回答。对于较新的预览版,这不再是问题。它刚刚开始工作。以前没有 WindowsMachine 选项,现在它可以正常工作,所以你所说的对于较新的预览来说是正确的,现在一切都很好。还是谢谢!
    猜你喜欢
    • 2023-01-03
    • 2011-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 2013-12-06
    相关资源
    最近更新 更多