I'm making a custom class dotnet new template and below is my template.json. This works but I can't figure out how to detect current namespace and replace it.
template.json:
{
"$schema": "http://json.schemastore.org/template",
"author": "name",
"classifications": [ "core", "console", "class" ],
"tags": {
"language": "C#",
"type": "item"
},
"identity": "Template.ClassTemplate",
"name": "Editable Class Template",
"shortName": "class",
"sourceName": "Class1"
}
C# template code file name is Class1.cs:
using System;
namespace newClass{
public class Class1{
}
}
command line to make new class:
dotnet new class -n class_name
resulting c# file below and is named class_name.cs:
using System;
namespace newClass{
public class class_name{
}
}
I would like to know how to detect the namespace so I can have the option to change it or have the namespace either detected and set automatically. Thanks!
You can specify on the command line with your own parameter.
I got this from the samples repo https://github.com/dotnet/dotnet-template-samples/tree/master/02-add-parameters
And it will replace the value in your source
Usage: