Question

In short, I need to run a text template file in another text template file.

Details: My Question is we have some bunch of .tt files and they basically combine several SQL files in one place. However, they are in a hyhreacy.

  1. Schema.tt
  2. InitialProductionData.tt
  3. TestData.tt

Basically, TestData.tt also contains all the .sql files generated by the other two along with some several other SQL files. InitialProduction.tt also contains the result SQL file of Schema.tt.

Each file is being used in different places so on.

The inside of the files look like this:

<#@ output extension=".sql" #>
<#@ include file="../Schema/InitialProductionData.sql" #>
SET NOCOUNT ON
GO
use [SomeDatabase]
GO
<#@ include file="HelloWorld.sql" #>
<#@ include file="GoogleData.sql" #>
<#@ include file="YahooData.sql" #>

But in order to run TestData.tt file correctly, I need to run other .tt files first. Why I need is that when I run TestData.tt, it automatically runs other ones in order and uses the resulted scripts to generate the final SQL script which contains everything.

Was it helpful?

Solution

I think you have two options: Use inlcudes instead of .tt's or write your generated code to SQL files from one template.

For the first approach, all you'd have to do is change the extensions on your .tt files to something like .ttinc and make sure they aren't set to auto generate. That way they only be run when included from another text template.

Then, you can include them like this:

<#@ include file="TestData.ttinclude" #>

Another option would be to write out the generated code to separate files from one master template. Oleg Sych has written about this on his blog.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top