This repository contains the code for MSBuild tasks that allow the expansion of Mustache templates during the build. Typically useful if you do any infrastructure as code with MSBuild or simply need to generate some files.
There are two main ways to run this. The most simple, is to use the MustacheExpand task. This takes a template and a data file as input and produce the expanded result in a file. The other way, MustacheDirectoryExpand, is to expand a directory structure where data can be overridden at every level. This mode becomes very useful is you are expanding configuration that does not support parameterization.
<MustacheExpand
TemplateFile="mustache-templates/simple.mustache"
DataFile="simple.json"
InputData="data1=value1"
DestinationFile="expanded.txt"/>
InputDatawill append to the data set or override values defined in theDataFile
To use the directory expansion, you need to declare the directory input and output structure that you want.
{
"Children": [
{
"Name": "First"
},
{
"Name": "Second",
"Children": [
{
"Name": "FirstChild"
}
]
}
]
}Then you can define parameters/data to the template expansion that override values downward in the tree structure
data
├── First
│ └── data.json
├── Second
│ └── FirstChild
│ └── data.json
└── data.jsonNow, you can declare the task and do a directory wise template expansion.
<MustacheDirectoryExpand
TemplateFile="app-resources.task.mustache"
DataRootDirectory="data"
DestinationRootDirectory="$(OutputPath)"
DefaultDestinationFileName="expanded.txt"
DefaultDataFileName="data.json"
DirectoryStructureFile="directory-structure.json" />Refer to the contribution docs.