BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Dependency Injection, Debugging added to T4 for Visual Studio 2012

by Jonathan Allen on Jun 08, 2012 |

There are quite a few improvements added to Visual Studio’s T4 system for Visual Studio 2012. The highlights include MEF support for deploying directive processors and easier debugging.

Directive processors are used to inject code and feed external data into a T4 template. In the past it could be quite tedious to develop and deploy directive processors. With VS 2012 and MEF it is supposed to become much simpler. To start with one needs to implement the IDirectiveProcessor interface. The details are not yet clear, but supposedly the attributes DirectiveProcessor and SupportedDirective handle the heavy lifting.

Preprocessed Templates have been renamed “Design-time templates”. For those of you who don’t know, a preprocessed template is a T4 template that has been compiled into a normal .NET assembly. Once this is done it loses its dependency on Visual Studio and can thus be called from any other application.

With Visual Studio 2012, developers gain the ability to add custom attributes to the classes that represent the preprocessed templates via directive processors. The specific use case in mind is adding MEF exports to the template class.

You can also change the visibility of the template class using the @template directive.

To address a bad interaction between Visual Studio and COM, the new ServiceProviderExtensions. GetCOMService function should be used instead of the normal GetService function. This is only needed when “using host-specific templates to access VS services”.

The final addition to T4 is easy template debugging. In the past you would need to add a debug directive and Debugger calls. Now you set simply set a breakpoint in your T4 templates, right-click on the file, and immediately start debugging.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT