template-validation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTemplate Validation
模板验证
This skill helps validate custom templates for correctness before publishing. It encodes the validation rules that catch common authoring mistakes — issues that cause templates to silently fail, produce broken projects, or not appear in .
dotnet newdotnet new list本技能可帮助在发布前验证自定义模板的正确性。它内置了验证规则,能够捕获常见的创作错误——这些错误会导致模板静默失败、生成损坏的项目或无法在中显示。
dotnet newdotnet new listWhen to Use
适用场景
- User asks to check or validate a template.json file
- User reports "my template doesn't show up after installing"
- User wants to review a template before packaging and publishing to NuGet
- User encounters unexpected behavior from a custom template
- 用户要求检查或验证template.json文件
- 用户反馈“我的模板安装后不显示”
- 用户希望在打包并发布到NuGet前审查模板
- 用户遇到自定义模板的意外行为
When Not to Use
不适用场景
- User wants to find or use existing templates — route to
template-discovery - User wants to create a project — route to
template-instantiation - User wants to create a template from an existing project — route to
template-authoring
- 用户想要查找或使用现有模板——请转至
template-discovery - 用户想要创建项目——请转至
template-instantiation - 用户想要从现有项目创建模板——请转至
template-authoring
Inputs
输入参数
| Input | Required | Description |
|---|---|---|
| template.json path | Yes | Path to the template.json file or the template directory containing |
| 输入 | 是否必填 | 描述 |
|---|---|---|
| template.json路径 | 是 | template.json文件的路径,或包含 |
Validation Rules
验证规则
When reviewing a template.json, check ALL of the following categories systematically. Report every finding as an error, warning, or suggestion.
审查template.json时,请系统检查以下所有类别。将每个发现结果报告为错误、警告或建议。
1. Required Fields
1. 必填字段
| Field | Severity | Rule |
|---|---|---|
| ERROR | Must be present and non-empty |
| ERROR | Must be present and non-empty |
| ERROR | Must be present and non-empty |
| WARNING | Without it, |
| WARNING | Improves template discoverability |
| SUGGESTION | Helps users understand what the template creates |
| SUGGESTION | Improves search and categorization (e.g., |
| SUGGESTION | Provides a fallback project name when |
| 字段 | 严重程度 | 规则 |
|---|---|---|
| 错误 | 必须存在且非空 |
| 错误 | 必须存在且非空 |
| 错误 | 必须存在且非空 |
| 警告 | 缺少该字段时, |
| 警告 | 有助于提高模板的可发现性 |
| 建议 | 帮助用户理解模板创建的内容 |
| 建议 | 有助于搜索和分类(例如: |
| 建议 | 当未指定 |
2. Identity Format
2. 标识格式
- ERROR if identity contains spaces — use dots or dashes (e.g., )
MyCompany.WebApi.CSharp - WARNING if identity has no namespace separator (or
.) — use reverse-DNS format-
- 如果identity包含空格则为错误——请使用点或短横线(例如:)
MyCompany.WebApi.CSharp - 如果identity没有命名空间分隔符(或
.)则为警告——请使用反向DNS格式-
3. ShortName Conflicts
3. ShortName冲突
The following short names conflict with dotnet CLI commands and will cause problems:
newbuildruntestpublishrestorecleanpackaddremovelistnugettoolslnhelp- ERROR if shortName matches any reserved name (case-insensitive)
- WARNING if shortName is only 1 character — too short for discoverability
- Note: shortName can be a string or an array of strings; check all values
以下短名称与dotnet CLI命令冲突,会导致问题:
newbuildruntestpublishrestorecleanpackaddremovelistnugettoolslnhelp- 如果shortName与任何保留名称匹配(不区分大小写)则为错误
- 如果shortName仅为1个字符则为警告——太短不利于发现
- 注意:shortName可以是字符串或字符串数组;请检查所有值
4. Symbol Validation
4. 符号验证
For each symbol in the object:
symbols- ERROR if a symbol is missing the field
type - For :
type: "parameter"- WARNING if no specified (defaults to
datatype)string - SUGGESTION if no (improves
descriptionoutput)--help - If :
datatype: "choice"- ERROR if no defined
choices - ERROR if is empty
choices - ERROR if is not in the choices list
defaultValue - WARNING if optional (not ) and no
isRequired— users get unexpected behaviordefaultValue
- ERROR if no
- If :
datatype: "bool"- ERROR if is not a valid boolean
defaultValue
- ERROR if
- If :
datatype: "int"- ERROR if is not a valid integer
defaultValue
- ERROR if
- Valid datatypes: ,
string,bool,choice,int,float,hextext - ERROR if datatype is not in the valid list
- WARNING if no
- For :
type: "computed"- ERROR if missing expression
value
- ERROR if missing
- For :
type: "generated"- ERROR if missing field
generator - Valid generators: ,
casing,coalesce,constant,port,guid,now,random,regex,regexMatch,switchjoin
- ERROR if missing
Parameter prefix collisions: WARNING if any parameter name is a prefix of another parameter name (e.g., and ) — this creates ambiguous parsing in expression contexts.
AuthAuthMode对于对象中的每个符号:
symbols- 如果符号缺少字段则为错误
type - 对于:
type: "parameter"- 如果未指定则为警告(默认值为
datatype)string - 如果没有则为建议(有助于提升
description输出的可读性)--help - 如果:
datatype: "choice"- 如果未定义则为错误
choices - 如果为空则为错误
choices - 如果不在choices列表中则为错误
defaultValue - 如果是可选参数(未设置)且没有
isRequired则为警告——用户会遇到意外行为defaultValue
- 如果未定义
- 如果:
datatype: "bool"- 如果不是有效的布尔值则为错误
defaultValue
- 如果
- 如果:
datatype: "int"- 如果不是有效的整数则为错误
defaultValue
- 如果
- 有效的数据类型:,
string,bool,choice,int,float,hextext - 如果datatype不在有效列表中则为错误
- 如果未指定
- 对于:
type: "computed"- 如果缺少表达式则为错误
value
- 如果缺少
- 对于:
type: "generated"- 如果缺少字段则为错误
generator - 有效的生成器:,
casing,coalesce,constant,port,guid,now,random,regex,regexMatch,switchjoin
- 如果缺少
参数前缀冲突:如果任何参数名称是另一个参数名称的前缀(例如:和)则为警告——这会在表达式上下文中导致解析歧义。
AuthAuthMode5. Sources Validation
5. 源验证
For source modifier conditions:
- WARNING if a condition string doesn't contain parentheses around symbol names — expected format is , not bare
(symbolName)symbolName
对于源修饰符条件:
- 如果条件字符串中的符号名称没有用括号包裹则为警告——预期格式为,而非裸写的
(symbolName)symbolName
6. Post-Action Validation
6. Post-Action验证
For each post-action:
- ERROR if missing
actionId - WARNING if missing — this text is shown to users when the action requires manual steps
description - SUGGESTION if missing — these are shown when the action can't run automatically (e.g., in an IDE)
manualInstructions
对于每个post-action:
- 如果缺少则为错误
actionId - 如果缺少则为警告——当操作需要手动步骤时,该文本会显示给用户
description - 如果缺少则为建议——当操作无法自动运行时(例如在IDE中)会显示这些说明
manualInstructions
7. Constraint Validation
7. 约束验证
For each constraint:
- ERROR if missing field
type - WARNING if missing — most constraint types require arguments
args
对于每个约束:
- 如果缺少字段则为错误
type - 如果缺少则为警告——大多数约束类型需要参数
args
8. Tags Validation
8. 标签验证
- SUGGESTION if no tag — adding
language(e.g.,tags.language) improves filtering in"C#"dotnet new list --language - SUGGESTION if no tag — adding
type(e.g.,tags.typeor"project") improves categorization"item"
- 如果没有标签则为建议——添加
language(例如:tags.language)有助于在"C#"中进行筛选dotnet new list --language - 如果没有标签则为建议——添加
type(例如:tags.type或"project")有助于分类"item"
Workflow
工作流程
Step 1: Locate the template.json
步骤1:定位template.json
The file can be at:
- Direct path:
path/to/template.json - In a template directory:
path/to/.template.config/template.json - In a directory:
.template.configpath/.template.config/template.json
文件可能位于:
- 直接路径:
path/to/template.json - 模板目录中:
path/to/.template.config/template.json - 目录中:
.template.configpath/.template.config/template.json
Step 2: Parse and validate
步骤2:解析并验证
Read the JSON. If it's malformed, report the JSON parse error with line number.
Run all 8 validation categories above. Collect errors, warnings, and suggestions separately.
读取JSON。如果格式错误,报告JSON解析错误及行号。
运行上述所有8个验证类别。分别收集错误、警告和建议。
Step 3: Report results
步骤3:报告结果
Present findings organized by severity:
- Errors (must fix) — template will not work correctly
- Warnings (should fix) — template may cause confusion or limited functionality
- Suggestions (nice to have) — improvements for discoverability and user experience
Include the total: "X error(s), Y warning(s), Z suggestion(s)"
按严重程度组织展示发现结果:
- 错误(必须修复)——模板无法正常工作
- 警告(应该修复)——模板可能导致混淆或功能受限
- 建议(可选优化)——提升可发现性和用户体验
包含统计总数:“X个错误,Y个警告,Z个建议”
Common Pitfalls
常见陷阱
| Pitfall | Impact |
|---|---|
| ShortName = "test" or "build" | Template can never be created — conflicts with CLI |
Missing | |
Choice parameter without | Confusing user experience on optional choice params |
Invalid | Template engine ignores the symbol, causing silent failures |
Computed symbol without | Template engine throws at instantiation time |
Parameter prefix collision ( | Ambiguous expression evaluation |
| Source condition without parentheses | Condition may not evaluate correctly |
| 陷阱 | 影响 |
|---|---|
| ShortName = "test"或"build" | 模板永远无法创建——与CLI命令冲突 |
缺少 | |
选择参数没有 | 可选选择参数的用户体验混乱 |
无效的 | 模板引擎会忽略该符号,导致静默失败 |
计算符号没有 | 模板引擎在实例化时抛出错误 |
参数前缀冲突( | 表达式求值歧义 |
| 源条件没有括号 | 条件可能无法正确求值 |
More Info
更多信息
- template.json reference — full schema
- Available Symbol Generators — generator types
- Post-action registry — action IDs
- Constraints — constraint types
- template.json参考文档——完整 schema
- 可用符号生成器——生成器类型
- Post-action注册表——操作ID
- 约束——约束类型