简体   繁体   English

令人失望的第一次 UNO 体验。 只有 WASM 有效

[英]Disappointing First UNO Experience. Only WASM works

I've spent the weekend and have still failed to get a "Hello, World" working.我已经度过了周末,但仍然无法让“Hello, World”正常工作。 Visual Studio:视觉工作室:

2022 Version 17.0.4
2022 Preview Version 17.1.0 Preview 1.1

uno-check says everything is fine: uno-check 说一切都很好: 在此处输入图像描述

Here are my runtimes:这是我的运行时: 在此处输入图像描述

Neither WUX or MUX (UWP or Desktop) flavors of WinUI work. WUX 或 MUX(UWP 或桌面)风格的 WinUI 都不起作用。 Android emulators coming up but the Hello World not deploying. Android 仿真器即将推出,但 Hello World 未部署。 Local Android device detected, but not deploying.检测到本地 Android 设备,但未部署。 Linux (Skia.GTK) not working. Linux (Skia.GTK) 不工作。

WASM IS able to display the text "Hello, World". WASM 能够显示文本“Hello, World”。

Wow.哇。 I was jazzed after watching every minute of the recent version 4 release conference.在观看了最近的第 4 版发布会议的每一分钟后,我感到很兴奋。 But if it is this difficult to just get the thing running..?但是,如果让事情运行起来就这么困难..? ? ?

I'm determined to get it working... but it appears to be a major unproductive project to do so.我决心让它工作......但这样做似乎是一个主要的非生产性项目。 Am I the only one in the world having difficulty?我是世界上唯一一个有困难的人吗?

Mark标记

December 19, 2001 2001 年 12 月 19 日

Ok, I was able to get WinUI (Desktop), WASM, Skia (WPF for Windows 7), Skia (Gtk for Linux), and Android working with "Hello, World".好的,我能够让 WinUI(桌面)、WASM、Skia(用于 Windows 7 的 WPF)、Skia(用于 Linux 的 Gtk)和 Android 与“Hello, World”一起工作。 Let me share what I learned and hopefully spare others this painful experience I've had.让我分享我学到的东西,并希望其他人能避免我所经历的痛苦经历。

Of course, before doing the following steps you'll want to install and run unocheck, so follow the documentation to do so and make sure all issues are resolved.当然,在执行以下步骤之前,您需要安装并运行 unocheck,因此请按照文档进行操作并确保所有问题都已解决。

Once you pass unocheck, then:一旦你通过了 unocheck,那么:

  1. First, forget about using .NET 6. They aren't ready.首先,忘记使用 .NET 6。它们还没有准备好。 This is what cost me most of my time.这是我花费最多时间的原因。 Uno 4 may advertise as .NET 6 compatible and they're getting close... but they are not there yet. Uno 4 可能会宣传为 .NET 6 兼容并且它们正在接近......但它们还没有。

  2. Forget about using project templates within Visual Studio.忘记在 Visual Studio 中使用项目模板。 Amazingly, even after releasing version 4.0 they haven't completed a template for the most important project that developers want: WinUI 3 Desktop.令人惊讶的是,即使在发布 4.0 版之后,他们还没有为开发人员想要的最重要的项目完成模板:WinUI 3 Desktop。 So, for now, just focus on using the CLI to install and invoke templates.所以,现在,只关注使用 CLI 安装和调用模板。

Open the cmd prompt and install templates with the following command: dotnet new -i Uno.ProjectTemplates.Dotnet打开 cmd 提示符并使用以下命令安装模板:dotnet new -i Uno.ProjectTemplates.Dotnet

This will install several templates.这将安装几个模板。 If you want to create a cross-platform based on WinUI 3 Desktop (Win32) version, then:如果要创建一个基于 WinUI 3 Desktop (Win32) 版本的跨平台,那么:

First create the containing folder (like "C:\Users\Mark\Code").首先创建包含文件夹(如“C:\Users\Mark\Code”)。 Then, using the command prompt, navigate to this folder and from within this folder enter the following command:然后,使用命令提示符导航到此文件夹,并在此文件夹中输入以下命令:

dotnet new unoapp-winui -o SolutionName dotnet new unoapp-winui -o 解决方案名称

This will produce a .NET 5 solution with a packaged WinUI 3 Desktop as the main development head.这将产生一个 .NET 5 解决方案,以打包的 WinUI 3 桌面作为主要开发头。 The WinUI 3 head will have a dependency on the latest WindowsAppSDK ver. WinUI 3 头将依赖于最新的 WindowsAppSDK 版本。 1.0 (formerly Project Reunion). 1.0(以前的项目重聚)。

DO NOT USE THE COMMAND:不要使用命令:

dotnet new unoapp-winui-net6 -o SolutionName dotnet new unoapp-winui-net6 -o 解决方案名称

This will produce a .NET 6 solution that will be screwed up and won't work.这将产生一个 .NET 6 解决方案,该解决方案将被搞砸并且无法工作。 Hopefully, they'll have all this corrected in the coming weeks.希望他们能在接下来的几周内纠正所有这些问题。 I would just wait until NVentive releases updated Templates for Visual Studio that support WinUI 3 for .NET 6. Then it will be easy to upgrade your solution from .NET 5 to .NET 6.我会等到 NVentive 发布更新的 Visual Studio 模板,支持 .NET 6 的 WinUI 3。然后将您的解决方案从 .NET 5 升级到 .NET 6 将很容易。

  1. When you run the dotnet new unoapp-winui -o SolutionName command, you will notice that several of the projects fail to "restore" properly:当您运行 dotnet new unoapp-winui -o SolutionName 命令时,您会注意到有几个项目无法正确“恢复”: 在此处输入图像描述

To solve this, use the command prompt to navigate into each of the failed projects and enter the command:要解决此问题,请使用命令提示符导航到每个失败的项目并输入命令:

dotnet restore点网还原

Now you're ready to use Visual Studio to launch your solution.现在您已准备好使用 Visual Studio 启动您的解决方案。 Select the WinUI 3 Packaging Project as your startup project and attempt to run "Hello, World". Select 将 WinUI 3 打包项目作为您的启动项目并尝试运行“Hello, World”。
4) You may get the error: "Error MSB3270 There was a mismatch between the processor architecture of the project being built "AMD64" and the processor architecture of the reference...". 4) 您可能会收到错误:“错误 MSB3270 正在构建的项目的处理器架构“AMD64”与参考的处理器架构不匹配......”。 If so, open your build configuration and check whether your packaging and main WinUI 3 project use different CPU targets as shown here (BFRLE is the name of my solution):如果是这样,请打开您的构建配置并检查您的打包和主 WinUI 3 项目是否使用不同的 CPU 目标,如下所示(BFRLE 是我的解决方案的名称): 在此处输入图像描述

I fixed this by changing the target platform of BFRLE.Windows.Desktop to x64 to match the packaging project.我通过将 BFRLE.Windows.Desktop 的目标平台更改为 x64 以匹配打包项目来解决此问题。 While you're in the configuration manager be sure that the Android project is deployed (otherwise it won't deploy during debugging).当您在配置管理器中时,请确保已部署 Android 项目(否则在调试期间不会部署)。

  1. Next, make sure that you install the GTK+3 runtime on your computer.接下来,确保在您的计算机上安装 GTK+3 运行时。 you can do so here:你可以在这里这样做:

https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases

The absence of this runtime is NOT checked for in unocheck.在 unocheck 中不检查此运行时的缺失。

  1. I also installed WSL.我还安装了 WSL。

At this point you ought to be able to run "Hello, World" as a local WinUI 3 Desktop app, as an IIS Express-hosted WASM app, as a Skia.WPF.Host app, and as a Skia.Gtk app.此时,您应该能够将“Hello, World”作为本地 WinUI 3 桌面应用程序、IIS Express 托管的 WASM 应用程序、Skia.WPF.Host 应用程序和 Skia.ZE6094CAAEAA604C8 应用程序运行I didn't try to run the MacOS or iOS flavors since these require physical hardware.我没有尝试运行 MacOS 或 iOS 风格,因为它们需要物理硬件。 I did try to connect my old Android phone (Galaxy Note 5, OS 7 API 24).我确实尝试连接我的旧 Android 手机(Galaxy Note 5,OS 7 API 24)。 To get a phone recognized of course you have to enable Developer Mode and enable USB Debugging (see online docs).当然,要让手机被识别,您必须启用开发人员模式并启用 USB 调试(请参阅在线文档)。 To get my phone recognized... had to disable Fast Deployment.为了让我的手机得到认可……必须禁用快速部署。 Even after this got my phone communicating, I was not able to successfully deploy to this old phone (I suspect I need to update my phone).即使在这让我的手机通信之后,我也无法成功部署到这个旧手机(我怀疑我需要更新我的手机)。

  1. In order to use a virtual Android emulator you need to go to the project properties of the Android project and ENABLE Fast Deployment and Incremental Android Packaging as shown below: In order to use a virtual Android emulator you need to go to the project properties of the Android project and ENABLE Fast Deployment and Incremental Android Packaging as shown below:

在此处输入图像描述

  1. You can accelerate your virtual Android emulator by enabling settings in Windows and your BIOS as explained here:您可以通过启用 Windows 和 BIOS 中的设置来加速虚拟 Android 仿真器,如下所述:

https://docs.microsoft.com/en-us/xamarin/android/get-started/installation/android-emulator/hardware-acceleration?pivots=windows https://docs.microsoft.com/en-us/xamarin/android/get-started/installation/android-emulator/hardware-acceleration?pivots=windows

The steps above finally got things working for me.上面的步骤终于让事情对我有用。 It didn't matter whether I was using VS 2022 or VS 2022 preview -- so that's one less thing you have to worry about.无论我使用的是 VS 2022 还是 VS 2022 预览版都没有关系——因此您不必担心这一点。

Now on to the more interesting problems of getting a real application to run cross-platform.现在讨论让真正的应用程序跨平台运行的更有趣的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM