Reputation: 34407
<#@ template debug="false" hostspecific="false" language="C#" #>
What does hostspecific attribute signify here.
Upvotes: 15
Views: 3163
Reputation: 6606
You can use the 'this.Host' property once the HostSpecific flag is set, which is of type ITextTemplatingEngineHost and allows you to do file path resolution among other things.
However, when used within Visual Studio (not at build time or from the command line), you can also cast the host to IServiceProvider and be connected to Visual Studio's global service provider.
This allows you to use any of Visual Studio's API's to find data for your template, or manipulate the project you're included in or similar actions.
A key scenario this enables is using the CodeModel (or soon Roslyn) to parse live source code in your project and use that as a source for generation metadata.
Upvotes: 6
Reputation: 2110
A template with hostspecific set to "true" can access a member this.Host
of type ITextTemplatingEngineHost
(MSDN). You can then use e.g. its method "ResolvePath" in order to locate files needed for input in the template.
This is even more useful when you use a custom templating engine. See Oleg's blog here: http://www.olegsych.com/2008/02/t4-template-directive/
Upvotes: 8