创建新的 .NET 6 MAUI 项目

rst*_*lze 3 c# maui .net-6.0

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

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

找不到匹配的模板:“maui”。
要列出已安装的模板,请运行“dotnet new --list”。
要在 NuGet.org 上搜索模板,请运行“dotnet new maui --search”。

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

Mat*_*ick 9

您可能尚未安装模板。当我第一次执行时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'.
Run Code Online (Sandbox Code Playgroud)

然后我跑了: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
Run Code Online (Sandbox Code Playgroud)

之后我就可以运行:

PS D:\Development\Technologies\MAUI\test-project> dotnet new maui
The template ".NET MAUI App" was created successfully.
Run Code Online (Sandbox Code Playgroud)