Scaffold.Tool
1.0.1-alpha
dotnet tool install --global Scaffold.Tool --version 1.0.1-alpha
dotnet new tool-manifest
dotnet tool install --local Scaffold.Tool --version 1.0.1-alpha
#tool dotnet:?package=Scaffold.Tool&version=1.0.1-alpha&prerelease
nuke :add-package Scaffold.Tool --version 1.0.1-alpha
Scaffold.Tool
Scaffold is a .NET command-line tool that helps you quickly generate boilerplate code for various components in your .NET applications. Code generation is based on self-defined templates, allowing you to customize the generated code to fit your team' and project's needs.
It promotes standardization and best practices by encouraging the use of consistent templates across your projects.
Why Scaffold?
- Speed: Quickly generate boilerplate code, reducing the time spent on repetitive tasks.
- Consistency: Ensure that generated code adheres to your team's coding standards and best practices.
- Customization: Easily create and modify templates to suit your specific project requirements.
- Lightweight: Minimal dependencies and easy to set up, ensuring a smooth integration into your development environment.
Installation
To get the most out of Scaffold, you can install it as a global tool:
dotnet tool install -g Scaffold.Tool
Alternatively, you can install it locally to a specific project:
dotnet new tool-manifest # only needed once per repo
dotnet tool install Scaffold.Tool
Getting Started
Once installed, start by adding a scaffold.json configuration file to the root of your project. This file defines your template configurations.
Example scaffold.json:
{
"collectionName": "MyCollection", // Arbitrary name for your collection of templates
"templateDirectory": "Templates", // Directory where your templates are stored, relative to the scaffold.json file
"templates": [
{
"key": "entity", // Unique identifier for the template
"template": "Entity.tpl", // Template file path, relative to the templateDirectory
"output": "Entities/{{ pascal_case name }}.cs", // Output file path (with placeholders)
"groups": ["crud", "domain"] // Groups this template belongs to
},
{
"key": "dto",
"template": "Dto.tpl",
"output": "Dto/{{ pascal_case name }}Dto.cs",
"groups": ["crud", "dtos"]
}
],
"snippets": [ // Snippets are templates that are to be inserted into existing files
{
"key": "register_service",
"template": "RegisterService.tpl",
"target": "Extensions/ServiceExtensions.cs", // Target file to insert the snippet into
"pattern": "services\\.AddScoped<[^>]+>\\(\\);", // Regex pattern to find the insertion point
"position": "after_last", // Position relative to the matched pattern (before, after, before_last, after_last)
"groups": ["crud", "service"]
},
{
"key": "map_api",
"template": "MapApi.tpl",
"target": "Program.cs",
"pattern": "^app\\.Map\\w+Api\\(\\);",
"position": "after_last",
"groups": ["crud", "api"]
}
]
}
Creating Templates/Snippets
Templates and snippets are simple text files with the .tpl extension. The powerful Scriban templating engine is used to process these files, allowing you to use variables, conditionals, loops, and more.
Additionally, Scaffold extends Scriban with custom functions to help with common tasks like automatic namespace generation and string casing transformations.
Example Template (Entity.tpl):
namespace {{ namespace }};
public class {{ pascal_case name }}
{
public Guid Id { get; set; } = Guid.CreateNew();
}
Example Snippet (RegisterService.tpl):
services.AddScoped<I{{ pascal_case name }}Service, {{ pascal_case name }}Service >();
Usage
After setting up your scaffold.json and creating your templates/snippets, you can generate code by running the following command in your project directory to eg. generate an entity named Product:
scaffold generate Product entity
Documentation
For detailed documentation, including advanced usage, like grouping and batch generating templates, conditonal feature inclusion, or out-of-project template access, please visit the Scaffold Documentation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1-alpha | 207 | 9/21/2025 |
| 1.0.0-alpha | 180 | 9/21/2025 |