TemGen 1.2.4

dotnet tool install --global TemGen --version 1.2.4
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local TemGen --version 1.2.4
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=TemGen&version=1.2.4
                    
nuke :add-package TemGen --version 1.2.4
                    

TemGen

.NET License: MIT

TemGen is a powerful template-based code generator that processes templates with embedded scripts to generate complete application code from simple definitions. It supports multiple scripting languages (C#, JavaScript, Python, Lua) and can generate entire project structures including backend services, WPF clients, and Blazor applications.

Table of Contents

Features

  • Multi-language scripting support: Embed C# (Roslyn), JavaScript (Jint), Python (IronPython), or Lua (MoonSharp) scripts in templates
  • Definition-based generation: Define your data models in simple text files
  • Full project generation: Generate complete application structures including:
    • Service backends
    • WPF desktop clients
    • Blazor web applications
    • Contracts, events, and DTOs
    • Tests and localization
  • Customizable templates: Create your own templates or compose the included default template layers
  • Composable template sources: Mix local template folders and git-backed template sources in the same project
  • Resource management: Copy and process resource files alongside generated code
  • Watch mode: Run in loop mode to continuously regenerate on demand

Installation

As a .NET Global Tool

dotnet tool install -g TemGen

From Source

git clone https://github.com/Najlot/TemGen.git
cd TemGen
dotnet build src/TemGen.slnx

Quick Start

  1. Create a project structure:
MyProject/
├── ProjectDefinition.json     # Project configuration
├── Resources.cs                # Optional resource copy script
├── Definitions/               # Your data model definitions
│   └── User                   # Example: User entity
├── Resources/                 # Optional static resources
└── Output/                    # Generated code will go here
  1. Define your project (ProjectDefinition.json):
{
  "Namespace": "MyApp",
  "DefinitionsPath": "./Definitions",
  "TemplatesPath": "../../Templates/Default_Backend;../../Templates/Default_DataAccess;../../Templates/Default_MVVM;../../Templates/Default_WPF",
  "OutputPath": "./Output",
  "ResourcesPath": "./Resources",
  "ResourcesScriptPath": "./Resources.cs",
  "ScriptsPath": "../../Templates/Default_Scripts"
}

Legacy ProjectDefinition files without the .json extension are still supported.

TemplatesPath can contain a semicolon-separated mix of local directories and git-backed sources. The included default application template is split into layers; list the folders you need in dependency order. Every default application layer requires Default_Backend.

Common combinations:

TemplatesPath:../../Templates/Default_Backend
TemplatesPath:../../Templates/Default_Backend;../../Templates/Default_DataAccess;../../Templates/Default_Blazor
TemplatesPath:../../Templates/Default_Backend;../../Templates/Default_DataAccess;../../Templates/Default_MVVM;../../Templates/Default_WPF

Layer dependencies:

Template Depends on Adds
Default_Backend none Contracts, ASP.NET Core service, service tests
Default_DataAccess Default_Backend Client data services, localisation, client data tests
Default_MVVM Default_Backend, Default_DataAccess Shared MVVM helpers and view models
Default_WPF Default_Backend, Default_DataAccess, Default_MVVM WPF desktop client
Default_Avalonia Default_Backend, Default_DataAccess, Default_MVVM Avalonia shared client and platform heads
Default_Blazor Default_Backend, Default_DataAccess Server-side Blazor client
Default_HTMX Default_Backend, Default_DataAccess Razor Pages/HTMX client

Use Default_Scripts as ScriptsPath with the default layers. Directory.Packages.props, README.md, and Todo.slnx are layered files; later templates append the package versions, README sections, and solution projects they require.

Each TemplatesPath entry may point either directly at a template directory or at a template source root that contains Template, Scripts, and Resources.*. When ScriptsPath or ResourcesScriptPath is omitted, TemGen discovers sibling Scripts directories and Resources.* scripts from each template source automatically.

Examples:

TemplatesPath:../../Templates/Default_Backend;../../Templates/Default_DataAccess;https://github.com/najlot/TemGen/tree/main/Templates/Default_Blazor
TemplatesPath:https://github.com/najlot/TemGen/tree/main/Templates/Default_Backend;https://github.com/najlot/TemGen/tree/main/Templates/Default_DataAccess;https://example.com/my-template-pack.git?ref=main&path=Templates/MyClient
  1. Create a definition (Definitions/CalendarEntry):
DateTime StartDateTime
string Title
string Description
int DurationInMinutes
  1. Generate code: Run temgen inside the folder with your ProjectDefinition.json or
temgen --path ./MyProject

Or if running from source:

dotnet run --project src/TemGen/TemGen.csproj -- --path ./MyProject

Project Structure

A TemGen project consists of:

  • ProjectDefinition.json: Configuration file specifying paths and global settings
  • Definitions/: Directory containing entity/model definitions
  • Templates/: Template files with embedded scripts
  • Scripts/: Reusable script files
  • Resources/: Static files to copy to output
  • Output/: Generated code destination

Repository Structure

TemGen/
├── src/
│   ├── TemGen/              # Main CLI application
│   └── TemGen.Tests/        # Unit tests
├── Templates/
│   ├── Default_Backend/     # Backend default layer
│   ├── Default_DataAccess/  # Client data default layer
│   ├── Default_MVVM/        # Shared MVVM default layer
│   ├── Default_WPF/         # WPF client default layer
│   ├── Default_Avalonia/    # Avalonia client default layer
│   ├── Default_Blazor/      # Blazor client default layer
│   ├── Default_HTMX/        # HTMX client default layer
│   └── Default_Scripts/     # Shared default helper scripts
└── Projects/
    └── Todo/                # Example Todo project
        ├── ProjectDefinition.json
        ├── Definitions/     # Example definitions
        └── Output/          # Generated output

How It Works

  1. Read Configuration: TemGen reads your ProjectDefinition.json file, or the legacy ProjectDefinition, to understand project structure
  2. Load Definitions: Parses definition files to understand your data models
  3. Process Templates: Iterates through templates, executing embedded scripts
  4. Execute Scripts: Runs C#, JavaScript, Python, or Lua code to generate output
  5. Write Output: Saves generated files to the output directory
  6. Incremental Updates: Only writes files that have changed

You can add arbitrary project settings directly in ProjectDefinition.json or the legacy ProjectDefinition and access them from templates. For example, "UserSecretsId": "aspnet-MyApp.Blazor-..." is available through Project.GetSetting("UserSecretsId"), and setting names like PrimaryColor are also exposed through the same settings collection.

Definition Files

Definition files use a simple format to describe data models:

# Basic properties
string PropertyName
int Count
DateTime CreatedAt

# References to other types
UserId Owner
TodoItemStatus Status

# Arrays
ChecklistTask[] Items

Supported Types

  • Primitive types: string, int, long, bool, DateTime, Guid, etc.
  • Custom types: Reference other definitions by name
  • Arrays: Append [] to any type
  • Nullable: Append ? to make properties nullable (when applicable)

Template Syntax

Templates are regular files with embedded script sections. Script sections are delimited by <#handler ... #> tags.

Supported Handlers

  • <#cs ... #>: C# scripts
  • <#js ... #>: JavaScript scripts
  • <#py ... #>: Python scripts
  • <#lua ... #>: Lua scripts
  • <#ref ... #> or <# ... #>: Reflection-based helpers

Example Template

using System;

namespace <#cs Write(Project.Namespace)#>.Models;

public class <#cs Write(Definition.Name)#>
{
<#cs 
    foreach (var entry in Definition.Entries)
    {
        WriteLine($"    public {entry.Type} {entry.Name} {{ get; set; }}");
    }
#>
}

Available Context Objects

In templates, you have access to:

  • Project: Project configuration (Namespace, paths, custom properties)
  • Definition: Current definition being processed (Name, Entries, properties)
  • Definitions: All definitions in the project
  • Write(), WriteLine(): Output methods
  • SetOutputPath(): Control output file path
  • SkipRemaining(): Use return SkipRemaining(); to stop processing the current template file immediately.

CLI Options

Usage: TemGen [options]

Options:
  -p, --path <path>         Path to a project definition file or folder
                            containing a ProjectDefinition.json or
                            ProjectDefinition file
                            [default: .]
                            
  -l, --loop                Run execution in a loop (watch mode)
                            
  --log-level <level>       Log level: Debug|Error|Fatal|Info|None|Trace|Warn
                            [default: Info]
                            
  -?, -h, --help            Show help and usage information
  --version                 Show version information

Examples

Generate once:

temgen --path ./MyProject

Watch mode (regenerate on demand):

temgen --path ./MyProject --loop

With debug logging:

temgen --path ./MyProject --log-level Debug

Example Project

The repository includes a complete Todo application example in Projects/Todo/:

Definitions

The Todo project defines entities like:

  • TodoItem: Tasks with title, content, status, checklist
  • User: User accounts
  • Note: Simple notes
  • TodoItemStatus: Enumeration for task status

Generated Output

From these simple definitions, TemGen generates:

  • Service Backend: ASP.NET Core service with repositories, controllers
  • Client Data Layer: API repositories, client services, and localization
  • MVVM Layer: Shared client view models and infrastructure
  • WPF Client: Desktop application with MVVM pattern
  • Avalonia Client: Cross-platform Avalonia application heads
  • Blazor App: Server-side Blazor web application
  • HTMX App: Razor Pages/HTMX web application
  • Contracts: Events, DTOs, interfaces
  • Tests: Unit tests for services and client data layer
  • Localization: Resource files for multi-language support

Try It

# Clone the repository
git clone https://github.com/Najlot/TemGen.git
cd TemGen

# Build TemGen
dotnet build src/TemGen.slnx

# Generate the Todo project
dotnet run --project src/TemGen/TemGen.csproj -- --path ./Projects/Todo

# Check the generated output
ls Projects/Todo/Output/

You can explore the generated projects:

cd Projects/Todo/Output
ls -la  # See all generated projects

Note: The WPF project requires Windows to build. The generated code structure demonstrates TemGen's capabilities.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
1.2.4 45 6/5/2026
1.2.3 47 6/4/2026
1.1.0 113 4/7/2026
1.0.1 137 1/14/2026