0

I create .template.config/template.json file in solution directory and run this command dotnet new --install {Solution Path}, it create template but when i create new project from this template it only changed the name of web project not changed the other projects name.

template.json file

<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>
Muhammad Ali
  • 173
  • 1
  • 6

2 Answers2

0

sourceName will be the string that is replaced during template usage with the new name. I have created complete solution with mutiple projects containing in filenames that string, as well in contents of the files.

dotnet new will do automatic replacement.

Here is sample repo and sourceName:

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

moljac
  • 946
  • 9
  • 12
0

In template.json

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

Then use -n parameter

dotnet new NcoreReferences -n ReplacedTemplate

More info about dotnet templates: How to create your own templates for dotnet new

CarlesD
  • 116
  • 6