18

I want to have a T4 template in a Visual Studio item template, but I don't want the "tt" file to appear in the project after the item has been added. In short, I want to generate a .cs file and then discard the .tt file completely. The code generation is a one time only occurrence when the item is added to the project.

I managed to get the .tt file added to the item template but I cannot see how to discard it after code generation.

Thanks Laurent

LBugnion
  • 6,672
  • 2
  • 24
  • 28
  • 4
    If it truly is a 1 time process, why not add the tt file to generate your cs file, then copy off the generated file, delete the tt file, then re-add the copied vs file to the project? The tt will create the actual csv file on disk. – Brocco Apr 27 '14 at 15:59
  • it is a one time occurrence when the item is added to the project, meaning "every time that a new item is added to the project". I need this step to happen automatically. – LBugnion Apr 27 '14 at 18:36
  • Understood, are you able to elaborate on the reason for this? The tt file is ignored by the compiler so this request seems to be purely cosmetic. What able a utility project that you can use to just process the files via a tt? – Brocco Apr 27 '14 at 22:43
  • 1
    This is for MVVM Light, an open source project I created. It is widely use in the xaml/c# community, including many developers who are not always experts. Adding a .tt file to the projects will bring some confusion, which I want to avoid. I don't need additional support request emails asking me what to do with this file. – LBugnion Apr 28 '14 at 04:47
  • 4
    Understood, I love and use that library in my WP apps. I would suggest creating a project for just doing the transforms for you that you do not include in your open source repository as it seems like a personal utility that you want to use but not share (for readability). And you can think of it like a tool similar to a Macro in a text editor. – Brocco Apr 28 '14 at 13:09
  • If your software comes with a Visual Studio extension, so if you ship code (or plan to) and not only templates, you could use the IWizard interface: https://msdn.microsoft.com/en-us/library/ms185301.aspx – Simon Mourier Dec 06 '15 at 17:50

1 Answers1

0

It's possible with tangible's tool shown here. It's not ideal, but with some finessing you can generate a file from one project containing the template into another. This then leaves the destination project free from templates.

Another approach is to generate a pre-processed template and then amend the generated file to create the output to a customised destination

Thundter
  • 582
  • 9
  • 22