Note that in the downloaded project, there is a folder labeled “.template.config” with a file inside it labeled “template.json”. Let’s review the contents of that file. Feel free to update this file with values you plan to use for your own project type, but you can leave these if you want to just continue with the demo.
01.
{
02.
"$schema"
:
"http://json.schemastore.org/template"
,
// https://github.com/dotnet/templating/wiki/Reference-for-template.json
03.
"author"
:
"Kyle Ballard"
,
04.
"classifications"
: [
"Web/MVC/Razor Pages"
],
// Use command 'dotnet new' to see list of other classifications
05.
"name"
:
"My Game Startup"
,
// Name that is displayed when running 'dotnet new' command
06.
"identity"
:
"MyGameStartup"
,
// Unique name for this template
07.
"shortName"
:
"mygamestartup"
,
// Alternative shortname, i.e. 'dotnet new mygamestartup'
08.
"tags"
: {
09.
"language"
:
"C#"
,
// Specify that this template is in C#.
10.
"type"
:
"project"
11.
},
12.
"sourceName"
:
"MyGameStartup"
,
// Will replace the string 'MyStartup' with the value provided via -n.
13.
"preferNameDirectory"
:
true
,
// If -n is not specified, will use name of the current directory
14.
"symbols"
: {
15.
"db"
: {
// If code or config contains {{Database_Name}} value will be replaced with parameter --db <value_here>
16.
"type"
:
"parameter"
,
17.
"isRequired"
:
"true"
,
18.
"datatype"
:
"string"
,
19.
"replaces"
:
"{{Database_Name}}"
,
20.
"defaultValue"
:
"MyGameStartupDB"
,
21.
"description"
:
"The database name attached to this project."
22.
}
23.
}
24.
}
I’ve added comments to the file so it is easy to understand, along with a link to the official documentation. There are more features than I am covering here if you wish to add them. A few noteworthy settings in the file are the “shortName” property. This is the trigger for your project, i.e. ‘dotnet new mygamestartup.’ Also, if you see the section labeled “symbols,” and then cross-reference this with the projects ‘appsettings.json’ file, you’ll see the connection string’s database will be replaced with the “–db” parameter once we run it.