Generate code automatically from templates. Simple, fast, and works on any project!
- β‘ Super Fast - Small (~2MB) and instant startup
- π Safe - Never overwrites your existing files
- π Works Everywhere - Windows, Linux, macOS (no installation needed)
- π Any Language - Works with C#, TypeScript, Python, Go, anything!
- π¨ Smart Variables - Auto-converts names (UserProfile β userProfile β user-profile)
Go to Releases and download the latest version:
- Windows:
codegen-win-x64.ziporcodegen-win-arm64.zip - Linux:
codegen-linux-x64.tar.gzorcodegen-linux-arm64.tar.gz - macOS:
codegen-osx-x64.tar.gzorcodegen-osx-arm64.tar.gz
π‘ Can't find downloads? Check all releases here
Use codegen from anywhere on your system.
macOS/Linux:
tar -xzf codegen-*.tar.gz
sudo mv codegen /usr/local/bin/codegen
# Now use from any directory
cd ~/my-project
codegen UserWindows:
# Extract zip, then move to a permanent location like:
move codegen.exe C:\bin\codegen.exe
# Add C:\bin to your PATH environment variable
# Then use from any directory:
cd C:\my-project
codegen UserKeep CodeGen in your project directory.
macOS/Linux:
tar -xzf codegen-*.tar.gz
mv codegen my-project/codegen
# Use with relative path
cd my-project
./codegen UserWindows:
# Extract and move to project
move codegen.exe my-project\codegen.exe
# Use with relative path
cd my-project
codegen.exe UserIn your project, create templates/model.template.txt:
// META: output=Models/{{EntityName}}.cs
public class {{EntityName}}
{
public int Id { get; set; }
public string Name { get; set; }
}# If installed globally:
codegen User
# If using locally:
./codegen User # macOS/Linux
codegen.exe User # Windowsβ
File generated: Models/User.cs
That's it! CodeGen created Models/User.cs with your template.
Templates are text files with special comments that tell CodeGen where to save the generated file:
// META: output=path/to/{{EntityName}}.cs
// META: tags=entity, model
// Your code here with {{EntityName}} variable
public class {{EntityName}} { }Add metadata at the top of your template files:
// META: output=Models/{{EntityName}}.cs
// META: description=Domain entity class
// META: tags=entity, model, domainAvailable Metadata:
output(required) - Path where the generated file will be saveddescription(optional) - Description of what the template generatestags(optional) - Comma-separated tags for filtering templates
When you run codegen UserProfile, these variables are replaced:
| Variable | Result | Example |
|---|---|---|
{{EntityName}} |
UserProfile | Class name |
{{entityName}} |
userProfile | Variable name |
{{ENTITY_NAME}} |
USERPROFILE | Constant |
{{entity-name}} |
user-profile | File/URL slug |
# Global installation
codegen User
codegen Product
codegen Order
# Local installation
./codegen User # macOS/Linux
codegen.exe User # WindowsGenerate only templates with specific tags:
# Generate only model (with "model" tag)
codegen --entity User --tags model
# Short form
codegen -e User -g model
# Multiple tags (generates templates with ANY of these tags)
codegen -e Product -g entity,service,controller
# Legacy format also works
codegen User templates modelHow Tags Work:
- If you don't specify tags, ALL templates are generated
- If you specify tags, only templates with at least ONE matching tag are generated
- Templates can have multiple tags:
// META: tags=entity, model, domain
Example:
// Template 1: model.template.cs
// META: tags=entity, model
// Template 2: service.template.cs
// META: tags=entity, service
// Template 3: controller.template.cs
// META: tags=entity, controller, apicodegen -e User -g model # Generates only template 1
codegen -e User -g service # Generates only template 2
codegen -e User -g entity # Generates all 3 (all have "entity")
codegen -e User # Generates all 3 (no filter)# Named arguments
codegen --entity User --templates my-templates
codegen -e User -t my-templates
# Legacy format
codegen User my-templates# macOS/Linux
for entity in User Product Order; do
codegen $entity
done
# Windows (PowerShell)
foreach ($entity in "User","Product","Order") {
codegen $entity
}project/
βββ templates-api/ # REST API templates
βββ templates-domain/ # Domain models
βββ templates-tests/ # Unit tests
codegen User templates-api
codegen Product templates-domain
codegen Order templates-tests# Named arguments (recommended)
codegen --entity <name> [--templates <path>] [--tags <tags>]
codegen -e <name> [-t <path>] [-g <tags>]
# Legacy format (still supported)
codegen <EntityName> [TemplatesFolder] [Tags]| Argument | Short | Description | Default |
|---|---|---|---|
--entity |
-e |
Entity name (required) | - |
--templates |
-t |
Templates folder path | templates |
--tags |
-g |
Filter by tags (comma-separated) | All templates |
--help |
-h |
Show help message | - |
# Basic usage
codegen --entity Product
codegen -e User
# Custom templates folder
codegen --entity Order --templates my-templates
codegen -e Customer -t ./api-templates
# Filter by tags
codegen --entity Invoice --tags entity
codegen -e Product -g model,service
# Combine all options
codegen -e Order -t templates -g entity,controller,service
# Legacy format (still works)
codegen Product
codegen User templates
codegen Order templates entity,serviceGlobal (Recommended for personal use):
- β
Use
codegenfrom anywhere - β Simpler commands
- β Team members need to install it
Local (Recommended for teams):
- β Commit to version control
- β Everyone has the same version
- β Works in CI/CD pipelines
- β Need to use
./codegenor full path
No! CodeGen never overwrites existing files. It's safe to run multiple times.
Any! CodeGen works with templates, so you can generate C#, TypeScript, Python, Go, or any other language.
No! The standalone executable includes everything needed.
Yes! Just run codegen EntityName my-folder
- .NET 9.0 SDK (for building from source)
./build-standalone.sh # macOS/Linux
build-standalone.bat # Windowsdotnet test- π« Report bugs or request features
- οΏ½ Download latest version
- οΏ½π‘ Check the templates folder for examples
- β Star this repo if you find it useful!
MIT License - feel free to use in your projects!
Made with β€οΈ using .NET 9.0