【问题标题】:How do I change the name of a dotnet new template when creating new projects?创建新项目时如何更改 dotnet new 模板的名称?
【发布时间】:2019-04-16 09:49:21
【问题描述】:

我创建了一个dotnet 模板,用于dotnet new。从这个模板创建新项目时,它可以正常工作,但是程序集和命名空间名称仍然是“模板”,而不是新项目。

我尝试创建一个新项目并使用--name 标志和--output 标志手动设置名称,但无济于事。

我怀疑我可以在某个地方使用一个变量,也许在 template.json 文件中?

谢谢,

【问题讨论】:

    标签: asp.net .net visual-studio .net-core


    【解决方案1】:

    您必须设置模板,然后使用 -n 等选项参数并给出名称。 例如,

    dotnet new web -n myBestName
    

    你可以看到更多关于 cli 来源click here

    【讨论】:

      【解决方案2】:

      您需要在template.json 文件中设置sourceName

      您可以参考此页面找到每个字段的用途。

      "sourceName": {
        "description": "The name in the source tree to replace with the name the user specifies",
        "type": "string"
      },
      

      http://json.schemastore.org/template

      template.json 文件的基本示例如下所示。注意sourceName

      {
          "$schema": "http://json.schemastore.org/template",
          "author": "Me",
          "classifications": [ "web api", "asp.net core", "C#" ],
          "identity": "WebApi.Template",
          "name": "WebApi.Template",
          "shortName": "WebApiTemplate",
          "tags": {
            "language": "C#",
            "type": "project"
          },
          "sourceName": "WebApi.Template",
          "preferNameDirectory" : true
        }
      

      如果您使用类似于上面的template.json,您可以在cli 命令中使用dotnet new YourTemplateName -n YourComponentName 或在以您的组件名称命名的文件夹中运行dotnet new YourTemplateName 来提供您的组件名称。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-06
        • 1970-01-01
        • 2018-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多