【问题标题】:Create multi projects template from command line从命令行创建多项目模板
【发布时间】:2019-01-06 19:00:53
【问题描述】:

我在解决方案目录中创建 .template.config/template.json 文件并运行此命令 dotnet new --install {Solution Path},它会创建模板,但是当我从该模板创建新项目时,它只更改了 web 的名称项目未更改其他项目名称。

template.json 文件

<pre>{
"$schema": "http://json.schemastore.org/template",
"author": "Muhammad Ali",
"classifications": [ "NcoreReferences" ],
"identity": "NcoreReferences",
"name": "NcoreReferences",
"shortName": "NcoreReferences",
"tags": {
"language": "C#",
"type":"solution"
},
"version":"1.0.0.0",
"preferNameDirectory":true,
"symbols": {
"projectname": {
  "type": "parameter",
  "dataType": "string",
  "fileRename": "NcoreReferences",
  "replaces": "NcoreReferences"
}
},
"sources": [
{
  "modifiers": [
    {
      "exclude": ["packages/**",".vs/**"]
    }
  ]
}
] }</pre>

【问题讨论】:

    标签: asp.net-core .net-core project-template


    【解决方案1】:

    sourceName 将是在模板使用期间用新名称替换的字符串。我已经创建了包含多个项目的完整解决方案,其中包含该字符串的文件名以及文件的内容。

    dotnet new 会自动替换。

    这里是示例 repo 和 sourceName:

    https://github.com/holisticware-xamarin/HolisticWare.DotNetNew.XamarinProjectsStructureTemplate/blob/master/Content/.template.config/template.json#L33

    【讨论】:

      【解决方案2】:

      在模板.json中

      {
      ...
      "sourceName": "OriginalTemplate",      // Will replace the string 'OriginalTemplate' with the value provided via -n.
      ...
      }
      

      然后使用-n参数

      dotnet new NcoreReferences -n ReplacedTemplate

      有关 dotnet 模板的更多信息: How to create your own templates for dotnet new

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多