views:

326

answers:

4

I need to create some files using Visual Studio T4 (templating). What is the best way to import some configuration settings into multiple .tt files and have it accessible in the templating code portion.

+1  A: 

I don't know a whole lot about T4, but it seems like while listening to Scott Hanselman's interview with Kathleen Dollard that she said the native Visual Studio T4 support does not allow multiple files. I seem to recall her mentioning an external harness for working with T4 allowing it though, and I know they mentioned Clarius Visual T4.

Chris Shaffer
+2  A: 

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

His blog is great - and has lots of T4 stuff in it.

Marc

marc_s
His blog is definitely the right place to go for T4.
vanja.
+1  A: 

I'd do this the same way as for any normal piece of code. Using AppSettings, or a custom configuration section. If you do it a lot, you should create a Custom Directive Processor. This could emit a property granting you access to the custom configuration.

John Saunders
+3  A: 

The simplest way to store configuration is by placing it as code in a shared .tt file, which you can include from multiple templates (i.e. if you need a connection string, make it a constant in a class feature block). However, if that is not an option and you need to access settings in .config file, I agree with John's suggestion.

Oleg Sych