如何构建 MAUI 应用以在 Windows 上启动
How to build MAUI app to start on Windows
我在 Windows 10 上使用 MSVS 2022 预览版 3.1 和 .NET 6.0.100-preview.7.21379.14,我能够创建一个 MAUI 应用程序并将其部署到 Android 模拟器。
我想 运行 在我的 Windows 上使用它,因为 Android 模拟器非常慢而且我对桌面更感兴趣。这目前可能吗?我尝试构建 WinUI 项目,它在磁盘上创建了一个可执行文件,但是当可执行文件启动时,没有任何反应。
我尝试使用“发布到文件夹”得到了相同的结果。我尝试再次使用 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:
问题似乎是 similar/same 到 https://github.com/dotnet/maui/issues/1557
您必须设置 WindowsMachine
目标和适当的框架。
然后按 F5 运行 并在 Windows 的设置应用程序中启用 Install from unknown sources
或类似功能,对我来说它自动弹出(我在 Win11)
然后您将获得应用 运行 调试工具:
我在 Windows 10 上使用 MSVS 2022 预览版 3.1 和 .NET 6.0.100-preview.7.21379.14,我能够创建一个 MAUI 应用程序并将其部署到 Android 模拟器。
我想 运行 在我的 Windows 上使用它,因为 Android 模拟器非常慢而且我对桌面更感兴趣。这目前可能吗?我尝试构建 WinUI 项目,它在磁盘上创建了一个可执行文件,但是当可执行文件启动时,没有任何反应。
我尝试使用“发布到文件夹”得到了相同的结果。我尝试再次使用 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: 问题似乎是 similar/same 到 https://github.com/dotnet/maui/issues/1557
您必须设置 WindowsMachine
目标和适当的框架。
然后按 F5 运行 并在 Windows 的设置应用程序中启用 Install from unknown sources
或类似功能,对我来说它自动弹出(我在 Win11)
然后您将获得应用 运行 调试工具: