Reputation: 51064
I've tried to resolve assembly reference pains in my T4 template by moving code out into a helper method in the same assembly and namespace as my template, but T4 refuses to find my helper method.
The helper method:
namespace PocoGenerator
{
public class EntityReflector
{
public static IEnumerable<PropertyInfo> GetPropertiesForTemplate()
{
var baseNameSpace = "";
var assemblyName = "DataObjects";
The recalcitrant template code:
<# foreach(PropertyInfo prop in PocoGenerator.EntityReflector.GetPropertiesForTemplate()) { #>
public <#= prop.PropertyType #> <#= prop.Name #> {get; set; }
<# } #>
Upvotes: 1
Views: 199
Reputation: 6606
T4 isn't compiling in the same context as your project code, so you'll need to use an assembly directive to load the output of your project.
So long as your'e using VS2010 SP1, you won't find any assembly locking issues with this.
However, this kind of recursive template that contributes to an assembly that it then helps to build can be fragile, as you need a version of the binary to bootstrap a clean build.
If at all possible, I'd move your helper code into an Helper assembly that's not part of your finished project, rather just a part of your toolset.
Upvotes: 1