Best way to save configuration settings for T4

I need to create some files using Visual Studio T4 (templating). What is the best way to import some configuration parameters into multiple .tt files and make them available in the template code part.

+6
c # visual-studio t4
source share
4 answers

The easiest way to save the configuration is to place it as code in a common .tt file, which you can include from several templates (i.e. if you need a connection string, make it a constant in the class function block). However, if this is not an option, and you need to access the settings in the .config file, I agree with John's suggestion.

+3
source share

Well, check out Oleg Sych ’s blog - he is the author of the T4 Toolbox, and it shows how you can output to multiple files. Not sure if T4Toolbox also includes configuration support - worth a look!

His blog is wonderful - and it has a lot of T4 stuff.

Mark

+2
source share

I would do it the same way as for any normal part of the code. Use AppSettings or a custom configuration section. If you do this a lot, you should create a Custom Directive Processor . This may return a property giving you access to a custom configuration.

+2
source share

I don’t know much about T4, but it seems that when listening to Scott Hanselman’s interview with Kathleen Dollard , she said that the built-in support for Visual Studio T4 does not allow the use of several files. I seem to recall that she mentioned the external suspension for working with T4, which allowed this, although I know that they mentioned Clarius Visual T4 .

+1
source share

All Articles