dotnet new --install 显示使用信息

dotnet new --install shows usage information

当我尝试使用以下方法安装新模板时:

dotnet new --install . --name MyTemplate

dotnet new --install "Path" --name MyTemplate

我得到使用信息:

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.

我有一个 .template.config 目录,其中有一个 template.json 文件。

template.json 文件的内容是这样的:

{
    "author": "My Department",
    "classifications": [
        "Solution Template"
    ],
    "name": "My Template Name",
    "identity": "My Template Identity",
    "shortName": "mytemplate",
    "tags": {
        "language": "C#"
    },
    "sourceName": "Company.Product",
    "preferNameDirectory": "true"
}

我当然希望它能告诉我哪里做错了。这在过去对我有用。

不幸的是,dotnet new --install 命令的工作方式有点混乱。可以安装成功但是输出结果不明显。您将获得使用信息和已安装模板列表,其中应包括您的新模板。

作为 , there is a bug filed 旨在整理它。

我看到了类似的结果 运行 dotnet new -i IdentityServer4.Templates,但是没有安装软件包,也没有显示任何错误或其他信息。

原来 nuget.org 没有配置为包源(我猜是新机器?- 虽然认为安装 visual studio 时默认配置)。

这是撰写本文时的 nuget.org 供稿:

https://api.nuget.org/v3/index.json

这里是配置它们的信息,以防它帮助那些没有这样做的人:

https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio#package-sources