t4

Debug tt templates in VS2008

Is there a way to debug tt files? I have installed SubSonic3 and all the templates do their job except the StoredProcedures.tt. It remains empty after 'Run Custom Tool'. ...

Using Microsoft T4 to create data access classes.

I'm new to T4 but I have stumbled accross it and it looks very useful. I'm trying to generate some simple DA classes and need some advice one a particular part of my code. Hoe can i generate the following code given that I already have the table name and column names (in this case "Agreements" and "AgreementId", "ContactId", etc)? if ...

VS Item Template Compiled Custom Parameter

I would like to create a custom parameter for a vstemplate containing some C# code. Basically I want to put DateTime.Now.ToString("yyyyMMddHHmmssfff") in my template (the formatted date, not the code). Basically I want to achieve the equivalent of the T4 below in my item template. [Migration(<#= DateTime.Now.ToString("yyyyMMddHHmmssfff"...

Run T4 text template programmatically

Is there a way to programmatically run T4 text templates from code? I'm making a custom domain specific language and I would like the related text templates to run every time the user saves. Currently, this is what I do in the DSL model: protected override void OnDocumentSaved(EventArgs e) { IVsCommandWindow commandWindow = (IVsComm...

How do you use .net Reflection with T4?

Hi all, I have a c# project which includes a Text Template. I would like this template to generate some SQL based on reflecting against the C# classes in the project. How does one access the current project's contents using T4? Is it possible, and if so, is Reflection available, or is it access to just the raw source that must then be ...

DataTable in T4 template

I'm creating a t4 template that will generate an enum from a number of values in our database. The weird thing is that as soon as I try to create a DataTable in the template code i get the ErrorGeneratingOutput message: <#@ template language="C#v3.5" debug="True" #> <#@ output extension="CS" #> <#@ assembly name="System.Data" #> <#@ as...

Are there any limitations on what libraries can be imported in a t4 template?

We're trying to learn to use T4 Templates. I have a desire to use the System.Data.Entity.Design.PluralizationServices library in order to better pluralize some Entity Model names within my template, but I've come across some issues in the achievement of this goal. Running code to generate output text. I think this is possible, but ...

How can I call Edit.FormatDocument on a file from within a T4 template?

I've got a T4 template (also using the T4Toolbox) that scans a folder for files, then processes them and kicks out .cs files. When the processing from the template is done, I want to format them with VS. I've got this far: IServiceProvider hostServiceProvider = (IServiceProvider)Host; EnvDTE.DTE dte = (EnvDTE.DTE)hostServiceProvider.Get...

T4 Templates and TextTemplatingFileGenerator

All the sudded T4 Templates stopped working on my machine. I get this error The custom tool 'TextTemplatingFileGenerator' failed. Specified cast is not valid. I tried to repair Visual Studio but no luck. Note I am running 64bit machine but 32bit Visual Studio 2008. What is odd is it worked great for some time then all the sudden s...

T4 Toolbox problems

I downloaded and installed the latest version of the T4 Toolbox for VIsual Studio 2010, in an attempt to create LINQ business objects, but I'm having some troubles with it. First, I was getting errors saying it couldn't find T4Toolbox.tt and T4Toolbox\LinqtoSql.tt in my project directory, but that's not where they are installed. Am I to...

Cannot get T4MVC to work with VS2010 and ASP.NET MVC 2

I'm trying to add the T4MVC templates to my project, but I'm experiencing some problems. I went to Codeplex and downloaded the latest version of T4MVC, and according to the instructions I just copied the two files T4MVC.tt and T4MVC.Settings.t4 into the root of my web application. Immediately, I got the following errors: From T4MVC.cs ...

T4 pro editors (payable) comparison

I'm interested in purchasing a full features T4 editor. I'm looking at: Tangible T4 Editor Professional Clarius Visual T4 Editor Professional They both have the same price tag (100$). Clarius' product seems a bit more feature rich, but is it really? And if it is, is it then more memory hungry as it's usual with rich Visual Studio pl...

Why does my T4 template append a number to the file name?

Why do my T4 templates sometimes append a number to the output file and sometimes not? For instance, in one case I might have a template file called Foo.tt and I'll get an output file of Foo.cs. In other cases, I'll get an output file of Foo1.cs. In every case, there is no other Foo.cs file that might be causing it to append a number. In...

Subsonic adding a DB provider for Simple Repository

Hey guys, I was wondering--what part of Subsonic 3 needs to be modified to support a different database under a Simple Repository scenario? I haven't found any documentation on this point. Subsonic 3 seems to be all about the T4 templates but when I check out the Subsonic project sources I don't see any T4 templates in there...so wher...

T4 Toolbox: How do I modify a pre-built template?

I'm using the T4 toolbox's Linq to SQL model to generate code, and I'd like to add some serialization properties to the code that it generates. I'm not sure how to modify the generator to do this. Would I modify the actual .tt file that is installed with the toolbox? Or can I add something to the .tt file that gets created for me? Or do ...

T4 Toolbox Linq to SQL Model: Association null after WCF call

I'm using the T4 toolbox Linq to SQL generator, and after making a WCF call, the association properties on my object are null and throwing a null reference exception in their setters. This is one such property: [DataMember(Order = 4, EmitDefaultValue = false)] [Association(Name = "Family_FamilyConfiguration", Storage = "familyConfigurat...

How to output namespace in T4 templates?

I have a T4 template for a class set up with TextTemplatingFileGenerator Custom Tool in Visual Studio: <#@ template language="C#v3.5" hostspecific="True" debug="True" #> <# var className = System.IO.Path.GetFileNameWithoutExtension(Host.TemplateFile); var namespaceName = "MyNamespace"; #> namespace <#= namespaceName #> { public...

T4 Template and Server.MapPath

I am trying to get the folder names inside the Views folder using T4 Template and it keeps giving me the following errors: Error 3 Compiling transformation: The name 'Server' does not exist in the current context c:\Projects\LearningASPMVC\LearningASPMVCSolution\LearningMVC\StronglyTypedViews.tt 20 47 Error 4 A namespace doe...

For what purposes have YOU used T4?

T4 has existed for several years in Visual Studio, but doesn't get a lot of attention. However, for those that know it, there seems to be some very creative and useful purposes. I am researching some different ways that T4 is used, and I would appreciate to hear how YOU may have used it for real life scenarios. I am primarily interest...

Creating a visual studio project directory using T4

I am trying to use T4 for source code generation. Mostly, I am able to generate individual files using it. Can you please provide me some information on how to create a complete visual studio directory (preferably separate from T4 template directory) having the below sample structure: /MyProject – Contains MyProject.sln. /app - Contains...