无法从输入的模板名称中确定所需的模板:blazorserverside

Hos*_*ani 5 c# asp.net-core blazor blazor-server-side

我正在尝试设置 blazor 服务器端,但是在尝试安装它时我一直遇到这个问题

按照microsoft 的本教程,我在 powershell 窗口中收到此错误

PS D:\blazorTesting> dotnet new blazorserverside -o WebApplicationServerSide
Usage: new [options]

Options:
  -h, --help          Displays help for this command.
  -l, --list          Lists templates containing the specified name. If no name is specified, lists all templates.
  -n, --name          The name for the output being created. If no name is specified, the name of the current directory is used.
  -o, --output        Location to place the generated output.
  -i, --install       Installs a source or a template pack.
  -u, --uninstall     Uninstalls a source or a template pack.
  --nuget-source      Specifies a NuGet source to use during install.
  --type              Filters templates based on available types. Predefined values are "project", "item" or "other".
  --dry-run           Displays a summary of what would happen if the given command line were run if it would result in a template creation.
  --force             Forces content to be generated even if it would change existing files.
  -lang, --language   Filters templates based on language and specifies the language of the template to create.


Unable to determine the desired template from the input template name: blazorserverside.
The following templates partially match the input. Be more specific with the template name and/or language.

Templates                                 Short Name            Language      Tags
---------------------------------------------------------------------------------------------------
Blazor (server-side)                      blazorserverside      [C#]          Web/Blazor
Blazor (Server-side in ASP.NET Core)      blazorserverside      [C#]          Web/Blazor/ServerSide

Examples:
    dotnet new blazorserverside
    dotnet new blazorserverside --auth Individual
    dotnet new --help
Run Code Online (Sandbox Code Playgroud)

dan*_*era 4

介绍

Dotnet Preview6 sdk 附带 Blazor 服务器端模板。仅当您想要创建托管、客户端或库时才需要安装模板。

要安装模板,您应该使用dotnet new -i模板名称和版本(可选

问题

当您添加模板时,您忘记设置模板的版本,您这样做了:

dotnet new -i Microsoft.AspNetCore.Blazor.Templates  # Bad. Don't copy-paste
Run Code Online (Sandbox Code Playgroud)

代替:

dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview6.19307.2
Run Code Online (Sandbox Code Playgroud)

因此,您是否有blazorserverside两次:每个版本一个。

解决方案

好消息,很容易修复。

第 1 步:删除错误的模板:

dotnet new -u Microsoft.AspNetCore.Blazor.Templates
Run Code Online (Sandbox Code Playgroud)

第 2 步:安装[可选]新的。请记住,您不需要此模板来创建服务器端 blazor 应用程序。

dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview6.19307.2
Run Code Online (Sandbox Code Playgroud)

享受您的实验室带来的乐趣。