【问题标题】:Unable to create custom template with custom name (-n) - dotnet new无法使用自定义名称 (-n) 创建自定义模板 - dotnet new
【发布时间】:2018-12-27 17:41:41
【问题描述】:

无法使用自定义名称 (-n) 创建自定义模板 - dotnet new

当我运行以下命令时,它正在创建一个解决方案 - 名称为 Test.sln

dotnet new sln -n Test.sln

这里 sln 是默认模板。

然而,如果我运行以下命令来创建 - custom template 使用其他名称,它仍然会在 default name 下提取模板。

dotnet new MessageHandler -n TestHandler

预计要创建/提取的 MessageHandler 是 - TestHandler.cs

然而,它在默认名称下提取/创建 - MessageHandler.cs

PS,

我正在按照以下链接创建自定义模板。

https://docs.microsoft.com/en-us/dotnet/core/tutorials/create-custom-template

对 Stackoverflow 社区的请求 - 请创建一个标签 - dotnet-new

【问题讨论】:

    标签: asp.net-core-2.0


    【解决方案1】:

    将 sourceName 添加到您的 .template.json 文件中,如下所示:

    {
    "$schema": "http://json.schemastore.org/template",
    "author": "phiree",
    ......
    "shortName": "TestHandler",
    "sourceName":"TestHandler"  <-----------this is the key
    }
    

    -n|--name 将替换“sourceName”,参考:

    https://reynders.co/create-your-own-templates-for-dotnet-new/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      • 2018-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      相关资源
      最近更新 更多