-
Notifications
You must be signed in to change notification settings - Fork 3
Template Configuration
Apoorv Rane edited this page Jun 29, 2022
·
9 revisions
Our template needs some configuration which includes the following:
- Projects that it contains
- Conditions for project creation
- Conditions for databases
- IDE configurations
- Command-line arguments
Configurations can be added by creating the .template.config folder in the root folder. .template.config folder contains following 3 files:
- template.json
- dotnetcli.host.json
- ide.host.json
Reference file: template.json
Some of the important properties:
- $schema: Sets the json schema and gives us intellisense for our json file.
- author: Sets the author of the template.
- classifications: An array of project types. This can be used for filtering in the Visual Studio new project dialog.
- name: Is the friendly/display name for the template.
- identity: Is a unique identifier for the template, I typically use the NuGet package id here.
- shortName: is the short name for the template that is used to invoke it with dotnet new (ex. dotnet new ninjamvc)
- tags: Tags for the template. These show up in the dotnet new list and can be used to filter in Visual Studio as well.
- sourceName: This one is important as it specifies the name/value in the source to be automatically replaced with the name of the generated project. Typically that includes the project name, project file name, default namespace etc.
- preferNameDirectory: This should generally be set to true for most templates. It determines if the directory name is used as the project name when a name is not specified.
- guids: GUIDs(right hand side ones) of each project to be created from sln file
- symbols: Project attributes that can be selected while creating the solution using this template which will be used for conditions within the solution
- sources: Contains modifiers for adding/removing projects based on attributes selected while creating the solution
Reference file: dotnetcli.host.json
This file is used to specify long names and short names for project attributes specified in template.json which can be used while creating the solution using dotnet cli.
Reference file: ide.host.json
This file is used to specify properties for project attributes specified in template.json which can be used while creating the solution from Visual Studio.