background preloader

T4

Facebook Twitter

What’s new with T4 in Visual Studio 2012 Release Candidate - Official T4 team blog. I’m a bit quicker off the mark than I was with our Beta as this is my first day back from vacation after our Release Candidate has launched.

What’s new with T4 in Visual Studio 2012 Release Candidate - Official T4 team blog

We have one final significant T4 feature to add for Visual Studio 2012 in addition to all of the stuff from out beta and developer previews, and it’s a doozy! T4 template debugging In past releases of Visual Studio, debugging T4 templates has been a little more work than we’d like, so we’ve addressed that in this release with a simple to use but full-featured debugging experience: You’ll see the ‘Debug T4 Template’ menu item above on the context menu for the template in the Solution Explorer.

There’s no need to set the debug flag on the template directive or any other special magic; just set a breakpoint in your T4 template and launch the debugger. I hope you enjoy the new productivity of debugging your T4 templates in our release candidate! Stuart kent's blog : T4 Roundup. Generating async WCF OperationContract signatures with a T4 template - Christian Weyer's Blog.

T4 template consuming a WCF service. It’s been a while since I’ve blogged since things have been crazy busy.

T4 template consuming a WCF service

I finally decided to kick myself and do a post so without further ado, the problem at hand: A co-worker of mine asked me whether its possible to dynamically create a type from some data he is receiving from a WCF service (over HTTP). My natural response was, why would you need to do that since Visual Studio creates a proxy from the metadata exposed by the service and the return types would typically be DataContracts. Well, it turns out that instead of returning a strongly typed domain specific object, the service is returning a Dictionary<string,string> where the Key represents an attribute and the Value represents the value of the attribute. This has obvious problems: The class definition would look something like this: public class User { public string Name {get;set;} public int Age {get;set;} public int Zip {get;set;} } Let’s create a simple service to simulate some data, nothing too fancy WSHttpBinding The.

Multiple outputs from T4 made easy – revisited. My multiple outputs from t4 made easy post contained a class making it easy to produce multiple files from Visual Studio’s text templating engine (T4).

Multiple outputs from T4 made easy – revisited

While useful it had a few issues: Getting start/end blocks mixed up resulted in unpredictable behaviourFiles were rewritten even when content did not changeDid not play well with source controlFiles not always deleted in VSFailed in Visual Studio’s project-less Web Sites This helper class forms the basis of multiple file output for Entity Framework templates in .NET 4.0 and the LINQ to SQL templates on CodePlex so we (Jeff Reed, Andrew Peters and myself) made the following changes. Improvements Simpler block handling The header, footer and file blocks can now be completed with EndBlock (EndHeader and EndFooter are gone), although it will automatically end the previous block when it hits a new one or the final Process method.

Skip unchanged files Automatic checkout Predictable clean-up Website projects fall back to single file generation. Create And Use T4 Templates? MSDN Library Design Tools Development Tools and Languages Mobile and Embedded Development Online Services patterns & practices Servers and Enterprise Development Web Development Show: © 2014 Microsoft.

Create And Use T4 Templates?

Please help us improve Microsoft is conducting an online survey to understand your opinion of the Microsoft Developer Network (MSDN). Privacy Statement. T4 (Text Template Transformation Toolkit) Code Generation - Best Kept Visual Studio Secret. t4talk. Blogs. Code Generation and T4 Text Templates. In Visual Studio, a T4 text template is a mixture of text blocks and control logic that can generate a text file.

Code Generation and T4 Text Templates

The control logic is written as fragments of program code in Visual C# or Visual Basic. The generated file can be text of any kind, such as a Web page, or a resource file, or program source code in any language. There are two kinds of T4 text templates: Run time T4 text templates ('preprocessed' templates) are executed in your application to produce text strings, typically as part of its output. For example, you could create a template to define an HTML page: <html><body> The date and time now is: <#= DateTime.Now #></body></html> Notice that the template resembles the generated output.

In addition, the template contains fragments of program code. To generate the output, your application calls a function that is generated by the template. String webResponseText = new MyTemplate().TransformText(); Your application can run on a computer that does not have Visual Studio installed. T4 Toolbox.