2

I want to know if it is possible to call the T4 custom tool TextTemplatingFileGenerator directly in VS2008, for e.g. using an addin.

The case I have is that I have metadata (xml) files in the solution. The T4 template reads these files to generate C# class files in the same folder as the metadata file.

Currently I have the T4 template scan the solution searching for a specific extension and creating files. It would be nice to be able to run an add-in that calls the template with the metadata file path. Note that I use the VS host quite extensively to add generated files to the projects.

I was wondering if I can call the TextTemplatingFileGenerator directly from within an add-in and if that would allow me to achieve what I want.

Also to be considered is that I am using the T4toolbox.

Regards, Ilias

ilias
  • 2,620
  • 2
  • 27
  • 37

1 Answers1

1

Yes, you can most certainly call the T4 service for an add-in. You won't need to use the TextTemplatingFileGenerator, which is mostly a thin wrapper around the service.

In an add-in, cast your DTE object to IServiceProvider and then ask it for STextTemplating.

Cast the result to ITextTemplating and then call the ProcessTemplate method for every template you want to transform. If you make multiple calls, then bracket them in calls to Begin/EndErrorSession to de-dupe output.

The callback and hierarchy parameters are optional.

GarethJ
  • 6,496
  • 32
  • 42