T4 Templating .sqlproj possible to build using MSBuild or TextTransform RRS feed

  • Question

  • Trying to process sqlproj T4 templates on the command line, happy to use TextTransform or MSBuild.

    Think (using TextTransform.exe) I need set -dp to get this directive to work <#@ SqlModelDirective processor="SqlModelDirectiveProcessor" #>

    Looking in Registry I get

    Microsoft.VisualStudio.Data.Tools.Package, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

    but cannot seem to get anything I try to work.

    Anybody know if it is possible to build templates from sqlproj's on the commandline?

    and if so how?

    Any help much appreciated.

    • Edited by OzzyGeoff Saturday, June 21, 2014 4:44 PM typo
    • Changed type OzzyGeoff Sunday, June 22, 2014 12:05 PM wrong type
    Saturday, June 21, 2014 4:40 PM

All replies

  • Unfortunately T4 templates which use the DacFx model do not run from the commandline.  There is some unique code when launching the directive processor which sites it with the model you wish to use.  Additionally the site must be serializable since it'll be marshaling data across the T4 app domain boundary. If you're interested in the details use ILSpy and check out SingleFileGenerator InvokeGenerator in Microsoft.VisualStudio.Data.Tools.Package.dll.

    Friday, July 18, 2014 3:44 PM
  • Many thanks
    Monday, July 21, 2014 6:50 AM
  • "go look at the decompiled sources" isnt a great answer and just creates more questions. 
    Sunday, November 24, 2019 4:31 PM
  • Hello OzzyGeoff,

    >Anybody know if it is possible to build templates from sqlproj's on the commandline?

    >and if so how?

    There are two thinks to understand.

    1. Two stages of T4 processing - compilation and execution.
    2. Interraction with Host.

    Code which process T4 source not only provide a conversion from T4 to VB/C# (with or without compilation) but also extract and put into Session some information from T4 source. Worse - part of this information is available only in Session and not available in the produced VB/C# code. 

    So, to get it work you need to use one of Host and fill Session with relevant information. What exactly need to be set - need to look in decompiled DSL code - T4 didn't contain this information.

    Look also

    Sincerely, Highly skilled coding monkey.

    Thursday, December 12, 2019 10:04 AM
  • Sorry, but it only way how to understand what happen inside - it's not clearly described... and not each time follow an existing description.
    And be shure that you will look on "very dirty" code...

    I do require to add one additional method to the produced code at compilation time or get option to replace code generation part when I need this. Tempalte compiler written so purly that it's almoust impossible to do anything with code generation. 

    Sincerely, Highly skilled coding monkey.

    Thursday, December 12, 2019 10:15 AM