vanja.
vanja.

Reputation: 2572

Best way to store configuration settings for T4

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.

Upvotes: 6

Views: 2230

Answers (4)

Oleg Sych
Oleg Sych

Reputation: 227

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.

Upvotes: 3

John Saunders
John Saunders

Reputation: 161783

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.

Upvotes: 2

marc_s
marc_s

Reputation: 754628

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

Upvotes: 1

Chris Shaffer
Chris Shaffer

Reputation: 32575

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.

Upvotes: 1

Related Questions