创建新的 .NET 6 MAUI 项目

Creating new .NET 6 MAUI project

我想使用 MAUI,因此安装了所有必要的东西(部分使用 maui-check)。

如一些教程中所述,我现在想从命令行使用 dotnet new maui 创建一个新项目。 但我只收到一条错误消息:

No templates found matching:'maui'.
To list installed templates, run 'dotnet new --list'.
To search for the templates on NuGet.org, run 'dotnet new maui --search'.

为什么我不能使用这个命令?

您可能还没有安装模板。当我第一次 maui-check 时,它说它无法安装工作负载;但随后的 运行 据说找到了它们。我的 dotnet new maui 会失败:

PS D:\Development\Technologies\MAUI\test-project> dotnet new maui -n HelloMaui
No templates found matching: 'maui'.
To list installed templates, run 'dotnet new --list'.
To search for the templates on NuGet.org, run 'dotnet new maui --search'.

然后我运行:dotnet new -i Microsoft.Maui.Templates

The following template packages will be installed:
   Microsoft.Maui.Templates

Success: Microsoft.Maui.Templates::6.0.100-preview.6.1003 installed the following templates:
Template Name         Short Name   Language  Tags
--------------------  -----------  --------  ------------------------------------------------
.NET MAUI App         maui         [C#]      MAUI/Android/iOS/macOS/Mac Catalyst/WinUI
.NET MAUI Blazor App  maui-blazor  [C#]      MAUI/Android/iOS/macOS/Mac Catalyst/WinUI/Blazor

之后我能够 运行:

PS D:\Development\Technologies\MAUI\test-project> dotnet new maui
The template ".NET MAUI App" was created successfully.