Template Smart Defaults

作者 dotnet0608d8924cd3MIT5.5K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Applies cross-parameter default rules when creating .NET projects with dotnet new, filling gaps consistently without overriding values the user set explicitly. USE FOR: choosing which target framework to pair with native AOT, deciding whether to keep HTTPS when authentication is enabled, recognizing that controllers and minimal-API flags are mutually exclusive, filling unset related parameters during project creation, explaining why a default was applied and ensuring an explicit user value is never overridden. DO NOT USE FOR: creating the project itself (use template-instantiation), finding or comparing templates (use template-discovery and template-comparison), authoring or validating custom templates (use template-authoring and template-validation).

AI 產生的概覽

在規劃 dotnet new 專案建立時補齊跨參數預設值,記錄每項選擇並輸出一條命令。

功能
此技能引導代理在使用者規劃建立 dotnet new 專案但未指定部分相關參數時補齊這些參數。它套用啟發式規則,例如將原生 AOT 與相容的目標框架配對、在啟用驗證時保留 HTTPS,以及避免同時使用互相矛盾的控制器與最小 API 旗標。它會產出一份「已套用預設值」記錄,將每個值標示為使用者設定或規則填入,並輸出一條僅包含實際傳遞旗標的精確 dotnet new 命令列。它絕不會覆寫使用者明確設定的值。
適用情境
當使用者要求建立 .NET 專案但未設定相關參數,或某個已選參數暗示另一個參數的合理取值時使用。它也用於解釋為何選擇某個預設值。它不用於實際建立專案、尋找或比較範本,也不用於撰寫與驗證自訂範本。
執行需求
僅為說明性內容,不附帶指令碼。它依賴可用的 dotnet CLI,以便透過 dotnet new --help 檢查範本,並要求代理能夠執行該命令。

Template Smart Defaults

This skill helps an agent fill in cross-parameter defaults when creating a dotnet new project. The rules below are guidance heuristics that keep related parameters consistent — they only fill gaps and never override a value the user set explicitly.

When to Use

  • The user asks to create a project but leaves related parameters unspecified
  • A parameter the user chose implies a sensible value for another parameter
  • You need to explain why a particular default was selected

When Not to Use

  • User wants to actually create the project — route to template-instantiation
  • User wants to find or compare templates — route to template-discovery or template-comparison
  • User wants to author or validate a custom template — route to template-authoring or template-validation

Inputs

InputRequiredDescription
Template short nameYesThe template the project will be created from (e.g., webapi)
Parameters already chosenYesThe parameter values the user has explicitly set
Available choicesRecommendedParameter names/choices from dotnet new <template> --help

Workflow

  1. Gather the parameters the user has explicitly set.
  2. Apply each rule below only where the corresponding parameter is unset — never override a value the user set explicitly.
  3. Confirm the chosen parameter names and choices against dotnet new <template> --help whenever the user asks for an exact command. This inspection does not create files and is worthwhile even for advice-only requests. Skip it only for a conceptual explanation that does not claim exact option names.
  4. Emit the two required outputs (see below) — this is what makes the skill decisive rather than inert.

For advice-only prompts that say "don't create files", make the displayed command safe to run by appending --dry-run. If a scenario needs a named example and the user omitted the name, choose a short descriptive sample name and mark it Source = rule. Do not add a name when the user asked for a command containing only explicitly requested choices or when the template can demonstrate those choices safely without one.

Required output

Always produce both, in this order:

A. A "Defaults applied" log — one row per parameter, covering both the explicit values you preserved (Source = user) and the gaps you filled by rule (Source = rule), so the user can see and override every choice:

ParameterValueSourceWhy
--frameworknet10.0ruleNative AOT (from --aot) needs the latest AOT-capable TFM
--authIndividualuserExplicitly requested — left unchanged
--nameAotWorkerruleAdded a descriptive sample name for this named example

Use Source = user for explicit values (never overridden) and Source = rule for gap-fills.

B. The exact single dotnet new command line you would run — include only the flags you are actually passing. Do not list flags you decided not to pass (e.g. don't mention --no-https when you are keeping HTTPS; don't mention a minimal-API flag when using controllers). Silence on an omitted flag is the correct, decisive signal.

Always emit a flag the user explicitly requested when the observed template help exposes it, even when its value matches the template default; this keeps intent visible and reproducible (for example, --auth None). Omit only inferred defaults that you are not actually passing. Boolean switches such as --no-https are passed without true.

AOT at create time vs publish time. --aot is a dotnet new flag only on the templates that expose it — always confirm with dotnet new <template> --help rather than assuming a given template does or doesn't offer it. There is no --publish-aot template flag — publish-time native AOT is enabled with the MSBuild property PublishAot=true (via dotnet publish or in the .csproj), not through dotnet new. Apply the framework rule only when the template actually offers --aot.

Rules

RuleDefault appliedRationale
--aot is set (on any template whose --help exposes it) and --framework is unsetSet --framework to the latest AOT-compatible framework the template offersNative AOT requires a recent, AOT-capable target framework; using the latest avoids build failures. (A framework already pinned by the workspace or global.json counts as set — keep it unless it's incompatible with AOT.)
--auth is anything other than NoneDo NOT pass --no-httpsAuthentication flows (cookies, tokens, redirects) require HTTPS; disabling it breaks auth.
--use-controllers is setDo NOT also pass a minimal-API flagControllers and minimal APIs are mutually exclusive program models; passing both is contradictory.
User set a value explicitlyLeave it unchangedSmart defaults only fill gaps; explicit user intent always wins.
Advice-only command must not create filesAdd --dry-runThe command itself must honor the no-write constraint, not only the agent's behavior.

When controllers are explicitly requested, the command must contain the controller option shown by --help; explaining controllers without passing the option is incomplete.

Validation

  • A "Defaults applied" log was produced with a Source (user/rule) and rationale per row
  • The exact single dotnet new command line was emitted, listing only flags actually passed
  • No parameter the user set explicitly was overridden
  • Only unset parameters were filled
  • Exact parameter names/choices were confirmed against dotnet new <template> --help, including for advice-only exact commands
  • A no-file advice command includes --dry-run
  • Boolean switches are emitted without a trailing true

Common Pitfalls

PitfallSolution
Treating heuristics as enforcementThese are guidance rules, not validation. Always confirm against dotnet new <template> --help choices, since parameter names vary by template.
Overriding an explicit user valueApply a rule only when the target parameter is unset.
Assuming a flag nameThe exact flag differs per template — always verify with --help (e.g. --aot is present only where --help lists it; controllers use --use-controllers).
Picking a framework the template doesn't supportUse the latest framework that appears in the template's --framework choices, not an arbitrary newest version.
Showing a plain creation command after "don't create files"Append --dry-run so the displayed command is safe to execute.

More Info

來源與署名

來源:dotnet/skills位於plugins/dotnet-template-engine/skills/template-smart-defaults提交0608d89

授權條款: MIT

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架