Skip to content

Preprocess T4 templates at build time - #95

Merged
joadan merged 1 commit into
mainfrom
buildtime-t4-preprocessing
Sep 7, 2026
Merged

joadan merged 1 commit into
mainfrom
buildtime-t4-preprocessing

Conversation

@joadan

@joadan joadan commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Templates were preprocessed only by Visual Studio's "Run Custom Tool", with the resulting .cs files checked in. A .tt edit made outside VS built and ran the old logic silently.

The generator csproj now runs the pinned dotnet-t4 local tool over every Templates***.tt before compiling, emitting a gitignored .g.cs beside each template. Editing a .tt and building is the whole loop, on any platform or IDE, and compile errors in template code point at the .tt file and line.

Turning this on surfaced one dormant edit: ScalarTemplate.tt referenced a non-existent GraphqlType.ScalarTypeName and had never been regenerated, so it had never compiled. Changed to scalarType.Name, matching the behaviour the shipped output already had.

Note this activates template edits that were written but never preprocessed: generated clients now carry XML doc comments, an ArgumentNullException guard on the client constructor and tidier indentation. The checked-in TestClient/TestClientNullable are left as they are; refreshing them is separate work.

Templates were preprocessed only by Visual Studio's "Run Custom Tool",
with the resulting .cs files checked in. A .tt edit made outside VS built
and ran the old logic silently.

The generator csproj now runs the pinned dotnet-t4 local tool over every
Templates\**\*.tt before compiling, emitting a gitignored <Template>.g.cs
beside each template. Editing a .tt and building is the whole loop, on any
platform or IDE, and compile errors in template code point at the .tt file
and line.

Turning this on surfaced one dormant edit: ScalarTemplate.tt referenced a
non-existent GraphqlType.ScalarTypeName and had never been regenerated, so
it had never compiled. Changed to scalarType.Name, matching the behaviour
the shipped output already had.

Note this activates template edits that were written but never
preprocessed: generated clients now carry XML doc comments, an
ArgumentNullException guard on the client constructor and tidier
indentation. The checked-in TestClient/TestClientNullable are left as they
are; refreshing them is separate work.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@joadan
joadan merged commit ac1fbd5 into main Sep 7, 2026
1 check passed
@joadan
joadan deleted the buildtime-t4-preprocessing branch September 7, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant