-
-
Notifications
You must be signed in to change notification settings - Fork 8
Hello World Plugin
Jeff Campbell edited this page Jun 14, 2021
·
6 revisions
With Genesis v2, code generation plugins are written as classes in .Net Core assemblies that are loaded by the Genesis.CLI
application.
This tutorial walks through how to create a new code generation plugin step by step.
- Create a new .Net Core Assembly Project targeting 3.1.X.
- Add the
Genesis.Plugin
Nuget package to your project.
- Create a new class
ExampleCodeGeneratorPlugin
. Add the following file contents below.
using Genesis.Plugin;
namespace HelloWorldPlugin
{
/// <summary>
/// An example code generation plugin that creates a single output class file.
/// </summary>
public class ExampleCodeGeneratorPlugin : ICodeGenerator
{
/// <inheritdoc />
public string Name => nameof(ExamplePlugin);
/// <inheritdoc />
public int Priority => 0;
/// <inheritdoc />
public bool RunInDryMode => true;
private string EXAMPLE_FILE_CONTENTS =
@"
public class ExamplePluginOutputClass { }
";
/// <inheritdoc />
public CodeGenFile[] Generate(CodeGeneratorData[] data)
{
return new CodeGenFile[]
{
new CodeGenFile(
"ExamplePluginOutputClass.cs",
EXAMPLE_FILE_CONTENTS,
Name)
};
}
}
}
- Build the project and copy the contents of the
bin
folder to a new folder in thePlugins
folder of yourGenesisCLI
installation. - Add the new plugin to your genesis config by either:
- If using Unity, you can update your
GenesisSettings
asset to include your new config by selecting theAuto Import
button on the inspector OR. - Generate a new Genesis config by opening the command line to the
GenesisCLI
installation folder and enteringdotnet genesis.cli.dll config create
OR. - Opening an existing genesis config and add the full type name (including namespace) of your
HelloWorldPlugin
to thevalue
entry of the key-value-pairs with keysGenesis.PreProcessors
andGenesis.AllPreProcessors
.
- If using Unity, you can update your
Redacted Example Json
{
"keyValuePairs": [
{
"key": "Genesis.CodeGenerators",
"value": "ExampleCodeGeneratorPlugin"
},
{
"key": "Genesis.CodeGenerators",
"value": "ExampleCodeGeneratorPlugin"
}
]
}
Done! From this point on when running code generation your new ExampleCodeGeneratorPlugin
should also execute.