user310291
user310291

Reputation: 38228

Can Visual Studio's Project-Templates use T4s?

I'm surprised to see no link between the 2. Am I wrong ?

I have some tt in a project template where I put $safeprojectname$ as filename to write and it doesn't seem to expand the tt file and create the cs file accordingly.

Upvotes: 0

Views: 428

Answers (2)

GarethJ
GarethJ

Reputation: 6605

You can use the two together. To get the custom tool set up, you need to do a little extra work in your .vstemplate file.

Here's the code from the standard TextTemplate itme template in VS 2010. The VSDesigner wizard code sets up the custom tool propery on the item.

 <TemplateContent>
    <ProjectItem TargetFileName="$fileinputname$.tt" ReplaceParameters="false">Prospective.CSharp.tt</ProjectItem>
    <CustomParameters>
      <CustomParameter Name="$itemproperties$" Value="CustomTool" />
      <CustomParameter Name="$CustomTool$" Value="TextTemplatingFileGenerator" />
    </CustomParameters>
  </TemplateContent>
  <WizardExtension>
    <Assembly>Microsoft.VSDesigner, Version=10.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
    <FullClassName>Microsoft.VSDesigner.ProjectWizard.ItemPropertyWizard</FullClassName>
  </WizardExtension>

Upvotes: 2

Mark Wilkins
Mark Wilkins

Reputation: 41252

Yes it can use them. Visual Studio recognizes files with a .tt extension as T4 template files and expands them appropriately. Oleg Sych has a lot of very good information about them. This one may be what you are looking for.

Upvotes: 1

Related Questions