it:ad:t4:howto:create_a_transformation

IT:AD:Transformations:T4:HowTo:Create a Transformation

If you write my.tt and stick an output directive on it, with an '.xx' extension attribute:

//This File is just a place holder.
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ output extension=".xx"#>

it gets immediately transformed to an output file called my.xx in the same directory that contains:

//This File is just a place holder.
PS: I was curious: It appears that it will always generate the output file (I took of the whole output directive to see what would happen, but it just defaulted to outputting tt.cs -- with no content.

Taking that a bit further:

 //This File is just a place holder.
  <#@ template language="C#" debug="false" hostspecific="true"#>
  <#@ include file="EF.Utility.CS.ttinclude"#>
  <#@ output extension=".cs"#>
  <#
  // Get the project's default namespace
  IServiceProvider serviceProvider = (IServiceProvider)Host;
  DTE dte = (DTE)serviceProvider.GetService(typeof(DTE));
  ProjectItem templateItem = dte.Solution.FindProjectItem(Host.TemplateFile);
  #>
  namespace <#= templateItem.ContainingProject.Properties.Item("DefaultNamespace").Value  #>.YourNameSpace 
  {
  //...
  }

Would produce a C# file with a namespace of your choosing.

  • /home/skysigal/public_html/data/pages/it/ad/t4/howto/create_a_transformation.txt
  • Last modified: 2023/11/04 23:03
  • by 127.0.0.1