How do you add an assembly reference programmatically?
Asked Answered
P

1

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?

Protect answered 8/11, 2012 at 17:55 Comment(4)
Couldn't you just append the assembly directive to the input text, at runtime?Golter
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?Pani
In this case, the T4 template is being processed at runtime at the point the ProcessTemplate method is invoked on the TextTemplating service.Protect
@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.Protect
C
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.

Cowl answered 23/11, 2012 at 16:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.