Wix & T4 : no "Custom Tool" option
Asked Answered
A

4

8

I want to generate a fragment using T4 but after adding a .tt file to the Wix project there is no "Custom Tool" option for this file. And there is no menu item "Run custom tool" when right clicking on the .tt file.

Is there a hack for this ? I'm using VS 2010 and latest Wix 3.5

Advised answered 1/9, 2010 at 16:34 Comment(3)
See below for my "hack". I am also using VS2010 and Wix 3.x.Penzance
I opened a feature request with the WiX team for this. Maybe you (or others) can add your voice to that issue? wixtoolset.org/issues/4657Chancellery
See this question as well stackoverflow.com/q/27983416/62662Chancellery
K
3

The Wix VS project system unfortunately doesn't support single file generators, so you won't get the default T4 experience.

You have a couple of choices. Oleg Sych's T4Toolbox has tools to run templates that target other projects, so you could run them in one project and target the output to your WiX project.

Alternatively, T4 has a simple service API STextTemplating. You could write a small VS add-in that does whatever generation you want in your Wix Project.

Karnak answered 12/9, 2010 at 2:37 Comment(0)
A
1

I've never used T4 let alone with WiX, but a google of it turns up several interesting hits including the last one asking what you are asking but no one ever knew the answer.

T4 template to generate Wix scripts to generate WCF MSIs in MSBuild

How to use MSBuild and Wix to create msi package...

[WiX-users] WiX 3.0 Support for T4 Templates in Visual Studio 2008]3

Almond answered 1/9, 2010 at 18:34 Comment(6)
Well at least I attempted to do some research for the poster with out saying something rude like "Let Me Google That For You". The question of T4 with WiX is soo obsecure that the chances of anyone ever providing a real answer is slim to none and slim just left town.Almond
@Christopher Not really that obscure. In WiX each included file has to be referenced manually so it's natural to want to find a way to automate this, and T4 is an obvious first choice.Penzance
@Hooligan, honestly, the fact that it took 18months for you to leave this comment illustrates how obsecure it is that someone would be interested in combining WiX and T4.Almond
+1 @BrianV It's not obscure it all. It's the same question I have. Most projects in visual studio support running T4 templates. WiX projects do not. My WiX projects would greatly benefit from this. How can it be done? Not obscure.Icelandic
@Ronnie Overby You could try what's suggested in my answer below. There are some drawbacks to this method, but it's better than adding a whole ton of files manually in my opinion.Penzance
It is obscure right up to the point where it suddenly becomes very useful indeed. I have a number of fragment files that are harvested using heat.exe. I manually edit the result to include a comment documenting the parameters passed to heat.exe. Now, it finally dawned on me that what I do by hand can easily be done with a T4 script! Letting others manhandle my setup project becomes a lot less daunting all of a sudden. Had it been possible that is. :( (My solution file has 97 projects and I try to avoid linking files between projects)Eleni
P
1

Using Gareth's suggestion of the T4 toolbox I was able to load in a T4 template, but it wasn't generating the file as expected.

What I ended up doing was creating a stub C# class project with my templates, and running a post-build command to copy the output to the WiX installer. Below is a working example.

WiX + T4 example

Here is a quick-and-dirty scripts that walks a folder structure and includes everything but whats in excluded files. It's at least a good starting point for adding files to your project on a folder-by-folder basis.

GetFiles.ttinclude - Utility methods to walk directory structure and maintain list of files

Files.tt - Generate WiX include

Penzance answered 17/3, 2012 at 18:53 Comment(2)
Files.tt changes your file's GUID every time the tt is ran. I believe that's bad. You'll want those ids to be consistent for each file over time.Icelandic
@Ronnie the way I used the code was to generate the initial install scripts then managed the files manually from that point on. Each file should have a unique guid, and if a file is to be update you'd want to give the new file a new guid and make sure the old file is removed.Penzance
E
1

If you have (or can create) another project in the same solution that does support T4 templates, there is a simple way to do it.

  1. Create the T4 template somewhere in that project
  2. In the WIX project, add the output file as a link (right click on project, Add Existing Item, Add As Link)
Eustashe answered 11/5, 2015 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.