T4
There are 2 entries for the tag
T4
In a previous post, Accessing app.config/web.config from T4 template, I provided an include template to provide access to the configuration file. In this post I present a stand-alone template, umm, template that you can stuff your own code into.
ConfigEnabledTemplate.tt
<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" language="C#v3.5" debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.Configuration.dll" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Configuration" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#
// <copyright file="c" company="Sky Sanders">
//
// This source is a Public Domain Dedication.
//
// http://salientt4.codeplex.com
//
// Attribution is appreciated.
//
// </copyright>
/// <summary>
/// This template can serve as a starting point for...
Code blocks in a T4 template are run in the context of the templating service and have no notion of app/web config.
Oleg Sych provides much detail on T4 Architecture.
To access configuration files in a template we have to drill down a few levels of abstraction to get a reference to the project hosting the template. From that point we can utilize classes from the Configuration namespace to closely approximate standard Configuration file behavior.
Presented here is a re-usable template, ConfigurationAccessor.tt, that can be included in a template to provide strongly typed access to the configuration file and hosting project, and...