Template Authoring
This skill helps an agent create and validate custom dotnet new templates. It guides bootstrapping templates from existing projects and validates template.json files for authoring issues before publishing.
When to Use
- User wants to create a reusable template from an existing .csproj
- User wants to validate a template.json for correctness
- User is setting up
.template.config/template.json from scratch
- User wants to package a template for NuGet distribution
When Not to Use
- User wants to find or use existing templates — route to
template-discovery or template-instantiation
- User has MSBuild issues unrelated to template authoring — route to
dotnet-msbuild plugin
Inputs
| Input |
Required |
Description |
| Source project path |
For creation |
Path to the .csproj to use as template source |
| template.json path |
For validation |
Path to an existing template.json to validate |
| Template name |
For creation |
Human-readable name for the template |
| Short name |
Recommended |
Short name for dotnet new <shortname> usage |
Workflow
Step 1: Bootstrap from existing project
Analyze the source .csproj and create a .template.config/template.json:
- Create
.template.config directory next to the project
- Generate
template.json with identity (reverse-DNS), name, shortName, sourceName (project name for replacement), classifications, and tags
- Preserve from source: SDK type, package references with metadata (PrivateAssets, IncludeAssets), properties (OutputType, TreatWarningsAsErrors), CPM patterns
Minimal example:
{
"$schema": "http://json.schemastore.org/template",
"author": "MyOrg",
"classifications": ["Library"],
"identity": "MyOrg.Templates.MyLib",
"name": "My Library Template",
"shortName": "mylib",
"sourceName": "MyLib",
"tags": { "language": "C#", "type": "project" }
}
Step 2: Validate template.json
Read and review the template.json for common authoring issues:
Validation checks to perform:
- Required fields — verify
identity, name, and shortName are present
- Identity format — use reverse-DNS format (e.g.,
MyOrg.Templates.WebApi)
- Parameter issues — check datatypes are valid (
string, bool, choice, int, float), choices have defaults, descriptions are present
- ShortName conflicts — avoid names that collide with built-in CLI commands (
build, run, test, publish). Check with dotnet new list to see if the name is already taken
- Post-action completeness — verify post-actions have all required configuration
- Tags — ensure language, type, and classification tags are set for discoverability
Step 3: Refine the template
Based on validation results and user requirements:
- Add parameters with appropriate types (string, bool, choice), defaults, and descriptions
- Add conditional content using
#if preprocessor directives for optional features
- Configure post-actions for solution add, restore, or custom scripts
- Set constraints to restrict which SDKs or workloads the template supports
- Add classifications and tags for discoverability
Step 4: Test the template locally
dotnet new install ./path/to/template/root
dotnet new mylib --name TestProject --dry-run
dotnet new mylib --name TestProject --output ./test-output
dotnet build ./test-output/TestProject
Validation
Common Pitfalls
| Pitfall |
Solution |
| Identity format issues |
Use reverse-DNS format (e.g., MyOrg.Templates.WebApi). Avoid spaces or special characters. |
| ShortName conflicts with CLI commands |
Avoid names like build, run, test, publish. Check by running dotnet new list to see if the name is already taken. |
| Missing parameter descriptions |
Every parameter should have a description and displayName for discoverability. |
| Not testing all parameter combinations |
Use dotnet new <template> --dry-run with different parameter values to verify conditional content works correctly. |
| Hardcoded versions in template |
Use sourceName replacement for project names and consider parameterizing framework versions. |
| Not setting classifications |
Add appropriate classifications (e.g., ["Web", "API"]) for template discovery. |
More Info
1---
2name: template-authoring
3description: >
4 Guides creation and validation of custom dotnet new templates. Generates templates
5 from existing projects and validates template.json for authoring issues.
6 USE FOR: creating a reusable dotnet new template from an existing project, validating
7 template.json files for schema compliance and parameter issues, bootstrapping
8 .template.config/template.json with correct identity, shortName, parameters, and
9 post-actions, packaging templates as NuGet packages for distribution.
10 DO NOT USE FOR: finding or using existing templates (use template-discovery and
11 template-instantiation), MSBuild project file issues unrelated to template authoring,
12 NuGet package publishing (only template packaging structure).
13license: MIT
14metadata:
15 source: https://skillmd.com/skills/aibot88/template-authoring
16---
17
18# Template Authoring
19
20This skill helps an agent create and validate custom `dotnet new` templates. It guides bootstrapping templates from existing projects and validates `template.json` files for authoring issues before publishing.
21
22## When to Use
23
24- User wants to create a reusable template from an existing .csproj
25- User wants to validate a template.json for correctness
26- User is setting up `.template.config/template.json` from scratch
27- User wants to package a template for NuGet distribution
28
29## When Not to Use
30
31- User wants to find or use existing templates — route to `template-discovery` or `template-instantiation`
32- User has MSBuild issues unrelated to template authoring — route to `dotnet-msbuild` plugin
33
34## Inputs
35
36| Input | Required | Description |
37|-------|----------|-------------|
38| Source project path | For creation | Path to the .csproj to use as template source |
39| template.json path | For validation | Path to an existing template.json to validate |
40| Template name | For creation | Human-readable name for the template |
41| Short name | Recommended | Short name for `dotnet new <shortname>` usage |
42
43## Workflow
44
45### Step 1: Bootstrap from existing project
46
47Analyze the source `.csproj` and create a `.template.config/template.json`:
48
491. Create `.template.config` directory next to the project
502. Generate `template.json` with `identity` (reverse-DNS), `name`, `shortName`, `sourceName` (project name for replacement), `classifications`, and `tags`
513. Preserve from source: SDK type, package references with metadata (PrivateAssets, IncludeAssets), properties (OutputType, TreatWarningsAsErrors), CPM patterns
52
53Minimal example:
54```json
55{
56 "$schema": "http://json.schemastore.org/template",
57 "author": "MyOrg",
58 "classifications": ["Library"],
59 "identity": "MyOrg.Templates.MyLib",
60 "name": "My Library Template",
61 "shortName": "mylib",
62 "sourceName": "MyLib",
63 "tags": { "language": "C#", "type": "project" }
64}
65```
66
67### Step 2: Validate template.json
68
69Read and review the `template.json` for common authoring issues:
70
71Validation checks to perform:
72- **Required fields** — verify `identity`, `name`, and `shortName` are present
73- **Identity format** — use reverse-DNS format (e.g., `MyOrg.Templates.WebApi`)
74- **Parameter issues** — check datatypes are valid (`string`, `bool`, `choice`, `int`, `float`), choices have defaults, descriptions are present
75- **ShortName conflicts** — avoid names that collide with built-in CLI commands (`build`, `run`, `test`, `publish`). Check with `dotnet new list` to see if the name is already taken
76- **Post-action completeness** — verify post-actions have all required configuration
77- **Tags** — ensure language, type, and classification tags are set for discoverability
78
79### Step 3: Refine the template
80
81Based on validation results and user requirements:
82
831. **Add parameters** with appropriate types (string, bool, choice), defaults, and descriptions
842. **Add conditional content** using `#if` preprocessor directives for optional features
853. **Configure post-actions** for solution add, restore, or custom scripts
864. **Set constraints** to restrict which SDKs or workloads the template supports
875. **Add classifications** and tags for discoverability
88
89### Step 4: Test the template locally
90
91```bash
92dotnet new install ./path/to/template/root
93dotnet new mylib --name TestProject --dry-run
94dotnet new mylib --name TestProject --output ./test-output
95dotnet build ./test-output/TestProject
96```
97
98## Validation
99
100- [ ] `template.json` passes manual validation with zero errors
101- [ ] Template identity and shortName are unique and meaningful
102- [ ] All parameters have descriptions and appropriate defaults
103- [ ] Template can be installed, dry-run, and instantiated successfully
104- [ ] Created projects build cleanly with `dotnet build`
105- [ ] Conditional content produces correct output for all parameter combinations
106
107## Common Pitfalls
108
109| Pitfall | Solution |
110|---------|----------|
111| Identity format issues | Use reverse-DNS format (e.g., `MyOrg.Templates.WebApi`). Avoid spaces or special characters. |
112| ShortName conflicts with CLI commands | Avoid names like `build`, `run`, `test`, `publish`. Check by running `dotnet new list` to see if the name is already taken. |
113| Missing parameter descriptions | Every parameter should have a `description` and `displayName` for discoverability. |
114| Not testing all parameter combinations | Use `dotnet new <template> --dry-run` with different parameter values to verify conditional content works correctly. |
115| Hardcoded versions in template | Use `sourceName` replacement for project names and consider parameterizing framework versions. |
116| Not setting classifications | Add appropriate `classifications` (e.g., `["Web", "API"]`) for template discovery. |
117
118## More Info
119
120- [Custom templates for dotnet new](https://learn.microsoft.com/dotnet/core/tools/custom-templates) — official authoring guide
121- [template.json reference](https://github.com/dotnet/templating/wiki/Reference-for-template.json) — full schema reference
122- [Template Engine Wiki](https://github.com/dotnet/templating/wiki) — template engine internals