locked
T4 conditional include directive RRS feed

  • Question

  • I'm using T4 inside of Visual Studio 2008 Team System.

    I have four templates (separated for readability) that all require the same include called "Common.tt" that I want to generate from a master file called "GenerateAll.tt." The issue I'm facing is figuring out whether or not "Common.tt" has already been included. Any ideas?

    Thursday, July 29, 2010 12:55 AM

Answers

  • I don't think this is possible. The directive itself doesn't support it and the C/C++ (#if !included)approach doesn't work because C# only allows defining preprocessor variables at the top of a source file.
    Oleg
    Thursday, July 29, 2010 11:48 AM
  • I think you can only do this by separating top-level from included files.

    GenerateAll.tt: 
       include common.txt
       include sub1.txt
       include sub2.txt

    DoSub1Only.tt:
       include common.txt
       include sub1.txt

    and so on.


    - Alan -MSFT
    Friday, July 30, 2010 10:58 AM
  • This would be a great issue to log on Microsoft Connect.
    Gareth Jones - Developer Architect - T4, UML Designer Extensibility [MSFT]
    Friday, July 30, 2010 5:39 PM

All replies

  • I don't think this is possible. The directive itself doesn't support it and the C/C++ (#if !included)approach doesn't work because C# only allows defining preprocessor variables at the top of a source file.
    Oleg
    Thursday, July 29, 2010 11:48 AM
  • I think you can only do this by separating top-level from included files.

    GenerateAll.tt: 
       include common.txt
       include sub1.txt
       include sub2.txt

    DoSub1Only.tt:
       include common.txt
       include sub1.txt

    and so on.


    - Alan -MSFT
    Friday, July 30, 2010 10:58 AM
  • This would be a great issue to log on Microsoft Connect.
    Gareth Jones - Developer Architect - T4, UML Designer Extensibility [MSFT]
    Friday, July 30, 2010 5:39 PM