Skip to content

Templates defect patterns

This page lists defects in ConnectSoft dotnet new templates and in the code generated from them. A template defect is usually invisible in the template repository itself, because the template builds with its default options. It appears only when someone generates a service with another combination of options, or updates a service from a newer template. Each pattern names the symptom, the cause, what to look for in a review, and how to prove the template is sound. The rules these patterns break are on the generated code page, and the template workflow is described in Contributing templates.

Conditionals and options

CS-DP-TPL-001: Template conditional evaluated differently by the template engine

Severity: major · Applies to: template · Enforced by: manual · Status: active

Symptom

A generated service fails to compile only for certain option combinations, with garbage at line 1, a stray #endif, or a missing type. The template repository itself compiles, because the C# compiler accepts the same conditionals.

Cause

The dotnet new engine processes conditionals before the compiler, and some forms are evaluated wrongly without an error:

  • An unparenthesised #if A || B is evaluated as #if A.
  • A false compound guard around a whole CRLF file that contains nested directives is not skipped cleanly.
  • A condition on a generated symbol that has replaces is ignored.
  • Conditions in .slnx files reject &&.

Check

  • Multi-symbol #if lines without parentheses.
  • Compound guards around whole files.
  • Generated symbols with both condition and replaces.
  • && in solution-file conditions.

Test

Generate and build each option combination that relies on a single operand of a compound condition.

CS-TPL-007, CS-TPL-008

CS-DP-TPL-002: Template guards one half of a pair

Severity: major · Applies to: template · Enforced by: manual · Status: active

Symptom

A generated variant fails with CS0535 or CS0246, cannot find an extension method, or throws ArgumentNullException at start.

Cause

The parts of an optional feature carry different conditions:

  • A registration or package reference sits under a symbol, but the file that uses it does not, or the other way round.
  • An options type whose members are all conditional generates no validator, while the registration still expects one.
  • An unconditional call needs a package or a settings section that only some variants include.

Check

For each symbol in the diff, the package reference, the using directives, the source files, the registration and the settings sections carry the same condition.

Test

Generate with the symbol off and on, then build and start both outputs.

CS-TPL-009, CS-TPL-007

CS-DP-TPL-003: Template symbol and MSBuild property disagree on an optional feature

Severity: major · Applies to: template · Enforced by: manual · Status: active

Symptom

A generated solution fails with CS1061 or CS0246 for an extension method whose call site is present.

Cause

The template engine keeps the call site because a template symbol is on, while a host-specific props file imported later forces the matching MSBuild property off and removes the file that defines the method from compilation.

Check

CI generation flags or template defaults that contradict MSBuild properties forced by host-specific props files.

Test

Generate with the exact CI flags, in solution form, and build.

CS-TPL-009, CS-TPL-007

CS-DP-TPL-004: Template option not applied to every generated file

Severity: major · Applies to: template · Enforced by: manual · Status: active

Symptom

Generated settings keep the default transport or storage, health-check paths gain a double slash, or the build fails because a property is not emitted.

Cause

The option rewrites the code, but not every settings variant or props file that carries the same value.

Check

For each template parameter, search the generated output for the default value that the parameter should replace.

Test

Generate with non-default parameters, and assert the settings values and a clean build.

CS-TPL-009, CS-TPL-004

CS-DP-TPL-005: Base-template default strips wiring the product requires

Severity: major · Applies to: template · Enforced by: manual · Status: active

Symptom

A service generated from a product template with default options answers 500 from its API description page and rejects requests the product must accept.

Cause

A default inherited from the base template, such as a gRPC-only service model, removes REST controllers and API description services that this product always needs.

Check

Base-template defaults that conflict with the fixed nature of the product, and whether the product template forces those symbols.

Test

Generate the product template with its defaults and run the product's acceptance tests.

CS-TPL-009, CS-TPL-004

CS-DP-TPL-006: Identifier carrying only part of the template source name survives generation

Severity: minor · Applies to: template · Enforced by: manual · Status: active

Symptom

Generated services keep type names that contain the template's own name.

Cause

The template engine replaces the full sourceName value. An identifier that contains only a shorter fragment of it is not renamed.

Check

New types, namespaces or symbols in a template that contain a fragment of sourceName rather than the full value.

Test

Generate a service under another name and search the output for fragments of the template's name.

CS-TPL-010

Template CI

CS-DP-TPL-007: Template CI builds only the default variant

Severity: major · Applies to: template, pipelines · Enforced by: manual · Status: active

Symptom

The template repository is green, and a service generated with a non-default option, or as the other artifact kind, does not build or arrives with empty fields. A validation script that would have caught it exists only on one workstation.

Cause

The template pipeline generates one artifact kind with default symbols. Code under #if for a non-default option, and exclude lists for option combinations, are never generated and built, so defects there stay latent. The validation tooling is not under version control.

Check

  • New template conditionals or exclude entries without a generated-and-built combination that covers them.
  • Validation scripts referenced from outside the repository.

Test

A pipeline matrix that generates, builds and tests every artifact kind and every supported option preset, with validators run from the repository.

CS-TPL-008, CS-TPL-007

Copies, snapshots and updates

CS-DP-TPL-008: Forked or snapshot copy of template output drifts from its source

Severity: major · Applies to: service, template · Enforced by: manual · Status: active

Symptom

A generated product fails CI after upstream changes, fixing one layer reveals the next failure, and fixes or flows present upstream are missing.

Cause

A template or service keeps a frozen copy of generated code, of a test harness, or of hand-refreshed snapshot files such as composed configuration, consumer symbols or a package snapshot, and CI never regenerates them.

Check

  • Edits to forked projects or snapshot files.
  • Submodule bumps that do not refresh the snapshot files.

Test

A CI step that regenerates the snapshots and fails when they differ from the committed copies.

CS-TPL-011, CS-TPL-001, CS-TPL-006

CS-DP-TPL-009: Service derived by copying another keeps the source's identity

Severity: major · Applies to: service, template · Enforced by: manual · Status: active

Symptom

A new service has metrics, exceptions and messages named after the source service's aggregates, collides with the source's ports, or misses a framework settings section at start.

Cause

A copy-and-rename realigns the domain layer but not the cross-cutting layers.

Check

In a new service, search for the source service's names, ports and settings keys.

Test

Start the new service beside the source and assert distinct ports, and run a settings-shape check.

CS-TPL-005

CS-DP-TPL-010: Clean three-way merge duplicates hand-ported code

Severity: major · Applies to: service, template · Enforced by: manual · Status: active

Symptom

After a service is updated from a newer template, the build fails on a duplicate member, or a test step binds twice.

Cause

Code that was ported by hand earlier sits in a different file from the one where the template now puts it, so the merge sees no conflict and keeps both.

Check

After a template-update merge, compare each merged file with fresh template output, and scan for duplicate members and step bindings.

Test

Build, and run the step-binding ambiguity check.

CS-TPL-012, CS-TPL-001, CS-TST-012

CS-DP-TPL-011: Hand edits to a generated file are reverted by regeneration

Severity: major · Applies to: service, library, api-client, blazor, template · Enforced by: manual · Status: active

Symptom

A fix from an earlier change disappears after the generator runs, and the diff looks harmless.

Cause

Entries were added to a file that carries a "do not edit" banner, without registering them in the generator's input.

Check

Changes to files with a generated banner that come without a change to the generator or its input.

Test

A drift test that pins the generated content, such as the exact set of emitted names, and runs the generator in CI.

CS-TPL-001, CS-TPL-003, CS-TPL-004