Question

My team is using T4 templates to generate some of our code based on and XML configuration file. Due to the parsing of the XML structure into a POCO we decided that using a common resource (A "master" T4 template) to parse and store the values for which all other T4 templates will use to generate their respective code. The ONLY T4 with the path to the XML is the Master template.

So by setting hostspecific="true" and setting the path relatively to the host, the Master T4 runs beautifully, however with the addition of (by using include file="...") and when one of the child T4 templates runs, the relative path of the XML is now not correct... It is looking for the XML file in a location now relative to the child.

The intention is that the Master will parse the XML and store the data in memory by ways of classes and properties, then the children only have to pull the information they need from the properties in the Master template.

Is a hostspecific solution possible for this?

Was it helpful?

Solution

Included files are copied in a class, generated from your child template. I did something similar to what you are trying to acomplish.

Add a field to master's template, that contains Path to masters template. In Masters template just use it.

<#@ template  debug="true" language="C#" hostSpecific="true" #>
<#@ output extension=".cs" #>

<#@ include file="..\\..\commonT4\master.ttinclude" #>


<#
  PathToMaster = @"..\\..\commonT4\";

OTHER TIPS

Instead of creating a template that refers to your 'master' template using 'include', why not place your 'master' template in a central location to the solution, then add the template as a link where required into the individual projects. This way the template runs in the project but is hosted from it's original location.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top