Skip to content

Getting started

Ilya edited this page Jul 10, 2016 · 6 revisions

Step 1

Create a console application project and install this library:

PM> Install-Package Generaid

I usually call this project "Generator". Set it as a startup project so that every time you want to generate code in your solution it runs.

Step 2

Add a class library project for the generated code. Let's call it "Generated".

Step 3

Add a "Runtime Text Template" project item. Let's call it "MyTemplate.tt". Add the following code in it:

<#@ template language="C#" #>

public sealed class HelloWorld
{
}

Step 4

Add a code file with a partial class class beside it, to make ourt template implement ITransformation interface, like this:

partial class MyTemplate : Generaid.ITransformer
{
    public string Name => "fileName.cs";
}

Make sure that the namespaces match between the halves of the partial class. The TransformText() method should be implement by the part generated from the *.tt file.

Step 5

To your Main() add the following code:

var builder = new HierarchyBuilder("../../Generated/Generated.csproj", "Folder")
{
    new NodeBuilder<MyTemplate>()
};
builder.Generate();

Step 6

Hit F5! If everything runs OK you will see Generated project updated

Clone this wiki locally