6

I'm using the T4 TextTemplating service from a VSPackage:

var t4 = this.GetService(typeof(STextTemplating)) as ITextTemplating;

Normally if a template is referencing types in an external assembly you can use the assembly directive. However, I don't know the assembly until runtime, so is there anyway of adding assembly references to the T4 engine programmatically?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
devdigital
  • 34,151
  • 9
  • 98
  • 120
  • 1
    Couldn't you just append the assembly directive to the input text, at runtime? – McGarnagle Nov 08 '12 at 18:02
  • I'm confused. T4 templates execute at design time, not runtime. So if you don't know your assembly reference at design time, how can you expect the T4 to know it? – Erik Funkenbusch Nov 08 '12 at 18:39
  • In this case, the T4 template is being processed at runtime at the point the ProcessTemplate method is invoked on the TextTemplating service. – devdigital Nov 08 '12 at 19:23
  • 1
    @dbaseman Yes that could be an option, I was wondering if there was a more structured approach, such as 'registering' the assembly with the templating engine or the host in which it runs. – devdigital Nov 08 '12 at 19:24

1 Answers1

2

I think the following may be a solution...

Write a custom host, see http://msdn.microsoft.com/en-us/library/bb126519.aspx

Before running the engine in that custom host, load the required assemblies using LoadFrom, see http://msdn.microsoft.com/en-us/library/1009fa28.aspx for details.

Xyzzy
  • 343
  • 2
  • 8