<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>[Profoundly Esoteric Image]</title><link>http://blogs.msdn.com/b/garethj/</link><description>GarethJ&amp;#39;s WebLog -  Code generation and abstraction</description><dc:language>en-GB</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/GarethjsWeblog" /><feedburner:info uri="garethjsweblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>52.211</geo:lat><geo:long>0.091</geo:long><image><link>http://blogs.msdn.com/garethj</link><url>http://blogs.msdn.com/photos/garethj/images/secondarythumb/GarethJ.aspx</url><title>GarethJ</title></image><item><title>What’s new with T4 in Visual Studio 2012 Release Candidate</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/zvtAd54gbn0/what-s-new-with-t4-in-visual-studio-2012-release-candidate.aspx</link><pubDate>Tue, 05 Jun 2012 01:52:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10314976</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10314976</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2012/06/05/what-s-new-with-t4-in-visual-studio-2012-release-candidate.aspx#comments</comments><description>&lt;p&gt;I’m a bit quicker off the mark &lt;a href="http://blogs.msdn.com/b/garethj/archive/2012/04/03/what-s-new-with-t4-in-visual-studio-11-beta.aspx"&gt;than I was with our Beta&lt;/a&gt; as this is my first day back from vacation after our &lt;a href="http://www.microsoft.com/visualstudio/11/en-us"&gt;Release Candidate has launched&lt;/a&gt;.&amp;#160; We have one final significant T4 feature to add for Visual Studio 2012 in addition to all of the stuff from out &lt;a href="http://blogs.msdn.com/b/garethj/archive/2012/04/03/what-s-new-with-t4-in-visual-studio-11-beta.aspx"&gt;beta&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/t4/archive/2011/09/25/what-s-new-with-t4-in-the-developer-preview-of-visual-studio-11.aspx"&gt;developer previews&lt;/a&gt;, and it’s a doozy!&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;T4 template debugging&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;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:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-36-85-metablogapi/8081.image_5F00_7F8DF6F0.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-36-85-metablogapi/0160.image_5F00_thumb_5F00_3F57DD76.png" width="700" height="549" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;You’ll see the ‘Debug T4 Template’ menu item above on the context menu for the template in the Solution Explorer.&amp;#160; 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.&amp;#160; You’ll have full access to step through your template code and look at variables in the locals window.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-36-85-metablogapi/5873.image_5F00_1413466F.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-36-85-metablogapi/2234.image_5F00_thumb_5F00_53DD2CF4.png" width="864" height="523" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;There’s also new service interface, &lt;font face="Courier New"&gt;IDebugTextTemplating&lt;/font&gt;, to allow folks who use T4’s Visual Studio API to call T4 asynchronously under the debugger and so build equivalent debugging facilities into their tools, plus a couple of new support pieces under the hood to enable all this whilst maintaining backward compatibility on our existing interfaces.&lt;/p&gt;  &lt;p&gt;I hope you enjoy the new productivity of debugging your T4 templates in our release candidate!&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:34d8691b-bff0-4fbc-8dd0-d78ecb4d1f3a" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2012" rel="tag"&gt;Visual Studio 2012&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Release+Candidate" rel="tag"&gt;Release Candidate&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Debugging" rel="tag"&gt;Debugging&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10314976" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=zvtAd54gbn0:_-52cT-4roQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio+2012/">Visual Studio 2012</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2012/06/05/what-s-new-with-t4-in-visual-studio-2012-release-candidate.aspx</feedburner:origLink></item><item><title>What’s new with T4 in Visual Studio 11 Beta?</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/Xcgk9EPyrGI/what-s-new-with-t4-in-visual-studio-11-beta.aspx</link><pubDate>Tue, 03 Apr 2012 02:14:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10290169</guid><dc:creator>GarethJones</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10290169</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2012/04/03/what-s-new-with-t4-in-visual-studio-11-beta.aspx#comments</comments><description>&lt;p&gt;Our &lt;a href="http://www.microsoft.com/visualstudio/11/en-us"&gt;beta release has been available&lt;/a&gt; for a couple of weeks now, so I thought it was about time I updated folks on what’s new for &lt;a href="http://msdn.microsoft.com/en-us/library/bb126445(v=vs.110).aspx"&gt;T4&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Everything below is in addition to the features and changes I noted in my previous post, &lt;a href="http://blogs.msdn.com/b/t4/archive/2011/09/25/what-s-new-with-t4-in-the-developer-preview-of-visual-studio-11.aspx"&gt;What’s new with T4 in the Developer Preview of Visual Studio 11?&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;OK, here goes…&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Directive processors are MUCH easier to build and more flexible        &lt;br /&gt;&lt;/strong&gt;Directive processors are T4’s plug-in mechanism.&amp;#160; They allow you to inject code into a template to pass and initialize parameters, or provide standard constructs within a template in a language-agnostic manner. However, they’ve been a bit fiddly to set up in the past and haven’t seen a lot of use.&amp;#160; This time, we’ve made them much cleaner and easier.       &lt;ul&gt;       &lt;li&gt;Directive processors can now be deployed as simple MEF components in a standard Visual Studio VSIX container. This means you can easily publish them on the Visual Studio gallery. There are new attributes &lt;font face="Courier New"&gt;[DirectiveProcessor]&lt;/font&gt; and &lt;font face="Courier New"&gt;[SupportedDirective]&lt;/font&gt; to make this easy. Look out for an example soon. &lt;/li&gt;        &lt;li&gt;Directive processors can now be built to run across Visual Studio versions as they only need to implement the new immutable interface type, &lt;font face="Courier New"&gt;IDirectiveProcessor&lt;/font&gt;. &lt;/li&gt;        &lt;li&gt;Directive processors can now &lt;a href="http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2083665-set-class-attributes-in-t4-output-class" target="_blank"&gt;add custom attributes to the underlying T4 class&lt;/a&gt;.&amp;#160; For example, it’s now really easy to create a directive processor to decorate a runtime template with MEF exports.&amp;#160; You simply implement the new method &lt;font face="Courier New"&gt;GetTemplateClassCustomAttributes&lt;/font&gt;().&amp;#160; I expect &lt;a href="http://msmvps.com/blogs/kathleen/"&gt;Kathleen&lt;/a&gt; to be all over this one! &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-36-85-metablogapi/8446.wlEmoticon_2D00_smile_5F00_4C9E5C95.png" /&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Cleanliness features for runtime templates        &lt;br /&gt;&lt;/strong&gt;We’ve finished the name transition from Preprocessed to Runtime templates in the beta including renaming the item templates and, as we’re now seeing a lot more usage of runtime templates, we’ve added a few cleanup features.       &lt;ul&gt;       &lt;li&gt;You can now control the visibility of the generated class, using the new &lt;font face="Courier New"&gt;visibility&lt;/font&gt; property on the &lt;font face="Courier New"&gt;&amp;lt;#@ template #&amp;gt;&lt;/font&gt; directive with values &lt;font face="Courier New"&gt;public&lt;/font&gt; or &lt;font face="Courier New"&gt;internal&lt;/font&gt;.&amp;#160; This means that if you’ve got runtime templates as part of a published assembly, they no longer have to be part of your public API. &lt;/li&gt;        &lt;li&gt;You can now turn off line pragmas for runtime templates with the new &lt;font face="Courier New"&gt;linePragmas&lt;/font&gt; property on the &lt;font face="Courier New"&gt;&amp;lt;#@ template #&amp;gt;&lt;/font&gt; directive with values &lt;font face="Courier New"&gt;true&lt;/font&gt; or &lt;font face="Courier New"&gt;false&lt;/font&gt;. This gives you more debugging options, as you can choose to either debug the original template or the generated code. This can also help if you’re finding the absolute filenames in pragmas are causing distracting merges under source code control. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;UI Simplification        &lt;br /&gt;&lt;/strong&gt;As part of Visual Studio 11’s &lt;a href="http://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-Studio-Toolbox-Simplification-of-the-Visual-Studio-11-Development-Environment" target="_blank"&gt;overall effort to simplify the UI&lt;/a&gt;, we’ve moved the &lt;font face="Courier New"&gt;Transform All Templates&lt;/font&gt; button out of the previously cluttered Solution Explorer toolbar.&amp;#160; You’ll now find it on the build toolbar and the build menu.&amp;#160; It also blocks the UI a bit less than it used to when you have lots of templates in your solution. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We hope you enjoy these new features.&amp;#160; As always, please give us feedback via &lt;a href="http://connect.microsoft.com/VisualStudio" target="_blank"&gt;Connect&lt;/a&gt; or &lt;a href="http://visualstudio.uservoice.com/forums/121579-visual-studio" target="_blank"&gt;UserVoice&lt;/a&gt;.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e0dbc393-ad1b-43dc-bcc0-9449b784b3c1" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+11+Beta" rel="tag"&gt;Visual Studio 11 Beta&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Code+Generation" rel="tag"&gt;Code Generation&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10290169" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=Xcgk9EPyrGI:BuD6RGmnjFQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Code+Generation/">Code Generation</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio+11+Beta/">Visual Studio 11 Beta</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2012/04/03/what-s-new-with-t4-in-visual-studio-11-beta.aspx</feedburner:origLink></item><item><title>Some nice new getting started with T4 videos</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/3zU-R0v2y58/some-nice-new-getting-started-with-t4-videos.aspx</link><pubDate>Wed, 30 Nov 2011 01:22:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10242653</guid><dc:creator>GarethJones</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10242653</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/11/30/some-nice-new-getting-started-with-t4-videos.aspx#comments</comments><description>&lt;p&gt;Kalle over at &lt;a title="http://abstractiondev.wordpress.com/" href="http://abstractiondev.wordpress.com/" target="_blank"&gt;abstractiondev&lt;/a&gt; has a nice series of videos getting started with T4 and developing a rich set of metadata to drive systematic generation.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://abstractiondev.wordpress.com/demo-videos/" href="http://abstractiondev.wordpress.com/demo-videos/"&gt;http://abstractiondev.wordpress.com/demo-videos/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;He’s also not afraid to promote his ideas with conviction, which is refreshing these days!&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3dd28d21-b685-40b7-afd3-f0cd5482eec3" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Videos" rel="tag"&gt;Videos&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10242653" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=3zU-R0v2y58:Y5Gy_opECWU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/11/30/some-nice-new-getting-started-with-t4-videos.aspx</feedburner:origLink></item><item><title>What's new with T4 in the Developer Preview of Visual Studio 11?</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/VNASrqPb3Nk/what-s-new-with-t4-in-the-developer-preview-of-visual-studio-11.aspx</link><pubDate>Sun, 25 Sep 2011 12:03:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10216338</guid><dc:creator>GarethJones</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10216338</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/09/25/what-s-new-with-t4-in-the-developer-preview-of-visual-studio-11.aspx#comments</comments><description>&lt;div class="wlWriterHeaderFooter" style="float:right; margin:0px; padding:0px 0px 4px 8px;"&gt;&lt;script type="text/javascript"&gt;digg_url = "http://blogs.msdn.com/b/garethj/archive/2011/09/25/what-s-new-with-t4-in-the-developer-preview-of-visual-studio-11.aspx";digg_title = "What's new with T4 in the Developer Preview of Visual Studio 11?";digg_bgcolor = "#FFFFFF";digg_skin = "normal";&lt;/script&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;&lt;/script&gt;&lt;/div&gt;&lt;p&gt;In among all the excitement of new ALM features like &lt;a href="http://blogs.msdn.com/b/bharry/archive/2011/09/19/the-new-team-explorer-in-tfs-11.aspx"&gt;integrated Code Review and MyWork&lt;/a&gt; to manage your daily workflow in the developer preview, there are, of course, a few nice new features for T4.&lt;/p&gt; &lt;p&gt;First of all, a naming change that's underway.&amp;nbsp; We've heard from you that 'Preprocessed' isn't the clearest choice of name for our templates, so we've switched to a new naming scheme:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Design-time templates - Templates that run in the VS IDE to produce output based directly on the template content  &lt;li&gt;Run-time templates - Templates that are preprocessed in the VS IDE to produce a class that you incorporate into your application for use at runtime. Calling a method on the class produces output based on the template content.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;For the Developer Preview, you'll see this change mostly in our documentation; the new terms will find their way into the product UI in time for Beta.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Now on to new features we've added in the preview:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;1) Improved template inheritance for runtime templates that need access to features of the host&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Previously, if you had a runtime template that declared itself as &lt;a href="http://www.olegsych.com/2008/02/t4-template-directive/"&gt;host-specific&lt;/a&gt;, &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;#@ template hostSpecific="true" #&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;it was hard to reuse the template through inheritance cleanly.&amp;nbsp; Derived templates that also declared host-specific would create a second 'Host" member that would hide the one from the base class, giving a warning.&lt;br&gt;To address this, we've added a third value for host-specific, "TrueFromBase", that makes the engine generate a host specific template, but expects the 'Host" property to come from the base class.&lt;/p&gt; &lt;p&gt;We've also made the comments generated from runtime templates more helpful.&lt;/p&gt; &lt;p&gt;&lt;br&gt;&lt;strong&gt;2) Better error processing for design-time templates&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;When your design-time template gets past the compile stage and starts to run the compiled code, T4 now accurately reports line numbers for any exceptions that get thrown.&lt;br&gt;Don't forget to set debug="true" to make sure the compiler is emitting line number information.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;3) COM Service helper&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;For folks using host-specific templates to access VS services, there've been a few reports of exceptions being thrown for one or two specific services.&lt;br&gt;Typically, it turns out that these services are written in managed code, but exposed over COM and then marshaled to T4's AppDomain over .Net Remoting. (Phew!)&lt;/p&gt; &lt;p&gt;This rather complex path leads to the exceptions, so we've included a simple extension method on IServiceProvider that you can use to get hold of those services and force them to behave properly:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static class ServiceProviderExtensions&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static Object GetCOMService(this IServiceProvider provider, Type type)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Just call this method instead of the regular GetService() method and your COM troubles should be over.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;4. Item templates now support LINQ out of the box.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;We've updated our VS item templates, so when you add a new T4 template to your VS project, you'll automatically get all the directives you need to use LINQ right off the bat.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;#@ assembly name="System.Core" #&amp;gt;&lt;br&gt;&amp;lt;#@ import namespace="System.Linq" #&amp;gt;&lt;br&gt;&amp;lt;#@ import namespace="System.Text" #&amp;gt;&lt;br&gt;&amp;lt;#@ import namespace="System.Collections.Generic" #&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;strong&gt;5. Correct disposal of MEF container when T4 AppDomain recycles.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;We provide a simple helper method (&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.texttemplating.vshost.compositionservices.initializeservices.aspx"&gt;CompositionServices.InitializeServices()&lt;/a&gt; ) to set up a MEF composition container in the T4 AppDomain if you want to use VS' MEF components from your template.&lt;/p&gt; &lt;p&gt;T4 has a heuristic that decides when to recycle the secondary AppDomain for design-time templates. This one is really more of a bug fix, but I'll mention it just because not many folks know about the MEF setup helper.&lt;br&gt;The fix is that now when the AppDomain gets recycled, the MEF container is correctly Disposed.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;We'll have some more features to talk about once the Beta comes along, but in the mean time, I hope you enjoy these improvements to T4 in our Developer Preview.&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e9923785-e38e-47de-8f8b-7d4c9c0d48f6" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/VS11" rel="tag"&gt;VS11&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10216338" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=VNASrqPb3Nk:TvmMvdIa83c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/09/25/what-s-new-with-t4-in-the-developer-preview-of-visual-studio-11.aspx</feedburner:origLink></item><item><title>DevArt joins the T4 Template Editor Fray</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/pr_444h8uw8/devart-joins-the-t4-template-editor-fray.aspx</link><pubDate>Thu, 02 Jun 2011 01:32:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10170530</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10170530</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/06/02/devart-joins-the-t4-template-editor-fray.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;We’ve now got a third contender in the Visual Studio T4 Editor space.&amp;#160; The good folks over at DevArt have joined the race. From their press release:&lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;Devart today releases a new powerful Visual Studio add-in for editing T4 templates with syntax highlighting, intellisense, code outlining, and all features of first-class text editor add-in for Visual Studio. It provides very high performance and makes creating T4 templates easier and faster.&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font size="2"&gt;With this new add-in, Devart offers a fast and easy way to create and edit T4 templates with multilevel template including, convenient template navigation, and rich code editing features.&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font size="2"&gt;So here’s my updated table of T4 editors (still &lt;/font&gt;&lt;font color="#000000" size="2"&gt;in strictly alphabetical order)&lt;/font&gt;&lt;/p&gt;  &lt;table style="list-style-type: disc" border="0" cellspacing="0" cellpadding="2" width="672"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="221"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="242"&gt;&lt;font color="#000000" size="2"&gt;Visual Studio 2010&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="207"&gt;&lt;font color="#000000" size="2"&gt;Visual Studio 2008&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="246"&gt;&lt;font color="#000000" size="2"&gt;&lt;a href="http://blog.visualt4.com/" target="_blank"&gt;Clarius Consulting&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="260"&gt;&lt;font color="#000000" size="2"&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/40a887aa-f3be-40ec-a85d-37044b239591" target="_blank"&gt;Get it&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="217"&gt;&lt;font color="#0066cc" size="2"&gt;&lt;u&gt;&lt;a href="http://www.t4editor.net/" target="_blank"&gt;Get it&lt;/a&gt;&lt;/u&gt;&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="254"&gt;&lt;a href="http://www.devart.com/t4-editor/" target="_blank"&gt;DevArt&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="265"&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/a42a8538-8d6e-491b-8097-5a8a00174d37" target="_blank"&gt;Get It&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="221"&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/abbd319b-45ff-4948-b071-17ac84a02ba6" target="_blank"&gt;Get It&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="256"&gt;&lt;font color="#000000" size="2"&gt;&lt;a href="http://t4-editor.tangible-engineering.com/T4-Editor-Visual-T4-Editing.html" target="_blank"&gt;Tangible Engineering&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="266"&gt;&lt;font color="#0066cc" size="2"&gt;&lt;u&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/60297607-5fd4-4da4-97e1-3715e90c1a23" target="_blank"&gt;Get it&lt;/a&gt;&lt;/u&gt;&lt;/font&gt;&lt;/td&gt;        &lt;td valign="top" width="222"&gt;&lt;font color="#0066cc" size="2"&gt;&lt;u&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/1A6C4FB2-7908-4721-92B3-61F2CEE92294/" target="_blank"&gt;Get it&lt;/a&gt;&lt;/u&gt;&lt;/font&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p style="list-style-type: disc"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="list-style-type: disc"&gt;&lt;font color="#000000" size="2"&gt;Keep on transforming those templates.&lt;/font&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d7f99372-44cb-431b-89c4-9c87ea58b9f5" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/VST4" rel="tag"&gt;VST4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/T4+Editor" rel="tag"&gt;T4 Editor&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10170530" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=pr_444h8uw8:mcGVINOA_Lo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Tech+thrills/">Tech thrills</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Community/">Community</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/06/02/devart-joins-the-t4-template-editor-fray.aspx</feedburner:origLink></item><item><title>Pluralcast Podcast on T4</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/aSpQScrJbX8/pluralcast-podcast-on-t4.aspx</link><pubDate>Fri, 06 May 2011 20:22:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10161934</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10161934</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/05/06/pluralcast-podcast-on-t4.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;A few weeks ago, I recorded a podcast about T4, and how it’s being used inside and outside Microsoft with the estimable &lt;a href="http://www.pluralsight-training.net/community/blogs/starr/default.aspx" target="_blank"&gt;David Starr&lt;/a&gt;, who I happened to meet up with at the recent &lt;a href="http://mvp.support.microsoft.com/gp/MVPsummit" target="_blank"&gt;MVP Summit&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;You can check it out in the &lt;a href="http://www.pluralsight-training.net" target="_blank"&gt;PluralSight&lt;/a&gt; &lt;a href="http://www.pluralsight-training.net/community/blogs/pluralcast/" target="_blank"&gt;Pluralcast blog&lt;/a&gt;. Enjoy.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.pluralsight-training.net/community/blogs/pluralcast/archive/2011/04/07/pluralcast-39-t4-with-gareth-jones.aspx"&gt;http://www.pluralsight-training.net/community/blogs/pluralcast/archive/2011/04/07/pluralcast-39-t4-with-gareth-jones.aspx&lt;/a&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:48170b5a-2332-42c4-8b92-dc6fed835f1e" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/PluralCast" rel="tag"&gt;PluralCast&lt;/a&gt;,&lt;a href="http://technorati.com/tags/PodCast" rel="tag"&gt;PodCast&lt;/a&gt;,&lt;a href="http://technorati.com/tags/VST4" rel="tag"&gt;VST4&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10161934" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=aSpQScrJbX8:fgWDi_Jh1ps:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Tech+thrills/">Tech thrills</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Community/">Community</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/05/06/pluralcast-podcast-on-t4.aspx</feedburner:origLink></item><item><title>New T4 blog and new T4 samples</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/bXPH7Bp2Shg/new-t4-blog-and-new-t4-samples.aspx</link><pubDate>Thu, 14 Apr 2011 01:04:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10153647</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10153647</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/04/14/new-t4-blog-and-new-t4-samples.aspx#comments</comments><description>&lt;p&gt;Some of you may have noticed that we’ve launched a new T4 official blog over at &lt;a href="http://blogs.msdn.com/b/t4"&gt;http://blogs.msdn.com/b/t4&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;We wanted a single place to consolidate information about T4, whether it be from my team that produces the core T4 engine or the teams within Microsoft that build on top and use T4 as their code generation strategy such as ADO.Net Entity Framework, WCF RIA Services, ASP.Net MVC Scaffolding, TFS Team Test, etc.&amp;#160; I’ll probably cross-post T4 entries there from now on.&lt;/p&gt;  &lt;p&gt;Mårten Rånge has posted a great series of T4 educational samples to help folks get off to a good start.&amp;#160; &lt;a href="http://blogs.msdn.com/b/t4/archive/2011/04/13/t4-samples.aspx" target="_blank"&gt;Check them out!&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:5bf72695-08a8-44bf-bd99-238e33e0a570" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/VST4" rel="tag"&gt;VST4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Code+Generation" rel="tag"&gt;Code Generation&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10153647" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=bXPH7Bp2Shg:NXgOw1VnaUg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Tech+thrills/">Tech thrills</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/04/14/new-t4-blog-and-new-t4-samples.aspx</feedburner:origLink></item><item><title>Hiring again</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/mYyTJU7Zbq8/hiring-again.aspx</link><pubDate>Fri, 25 Mar 2011 07:33:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10145734</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10145734</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/03/25/hiring-again.aspx#comments</comments><description>&lt;div class="wlWriterHeaderFooter" style="float:right; margin:0px; padding:0px 0px 4px 8px;"&gt;&lt;script type="text/javascript"&gt;digg_url = "http://blogs.msdn.com/b/garethj/archive/2011/03/25/hiring-again.aspx";digg_title = "Hiring again";digg_bgcolor = "#FFFFFF";digg_skin = "normal";&lt;/script&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;&lt;/script&gt;&lt;/div&gt;&lt;p&gt;Folks, if you want to work on Visual Studio, here's your chance.&lt;/p&gt; &lt;p&gt;We've two openings for senior developers on my team working on building WPF-based experiences and the underlying infrastructure for agile/enterprise team dev tools.&lt;/p&gt; &lt;p&gt;&lt;a href="http://bit.ly/gb8P76"&gt;http://bit.ly/gb8P76&lt;/a&gt; &amp;amp;&amp;amp; &lt;a href="http://bit.ly/gjHsqC"&gt;http://bit.ly/gjHsqC&lt;/a&gt;  &lt;p&gt;&amp;nbsp; &lt;p&gt;Apply through the jobs site and ping me or just get in touch directly.&lt;/p&gt; &lt;p&gt;C'mon, let's see those resumes.&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:bbc9e6ff-9b10-4195-b8a6-b40c26bfb618" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Hiring" rel="tag"&gt;Hiring&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Vacancies" rel="tag"&gt;Vacancies&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;,&lt;a href="http://technorati.com/tags/agile" rel="tag"&gt;agile&lt;/a&gt;,&lt;a href="http://technorati.com/tags/enterprise+team" rel="tag"&gt;enterprise team&lt;/a&gt;,&lt;a href="http://technorati.com/tags/WPF" rel="tag"&gt;WPF&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10145734" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=mYyTJU7Zbq8:0Rl2CrQloBU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/The+real+world/">The real world</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/03/25/hiring-again.aspx</feedburner:origLink></item><item><title>T4 vs Razor – what’s the skinny?</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/g-OCw_pJjaQ/t4-vs-razor-what-s-the-skinny.aspx</link><pubDate>Fri, 11 Mar 2011 02:43:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10139639</guid><dc:creator>GarethJones</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10139639</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/03/11/t4-vs-razor-what-s-the-skinny.aspx#comments</comments><description>&lt;p&gt;You might have noticed in the &lt;a href="http://weblogs.asp.net/scottgu/archive/2011/01/13/announcing-release-of-asp-net-mvc-3-iis-express-sql-ce-4-web-farm-framework-orchard-webmatrix.aspx"&gt;recent storm of Web Tools releases&lt;/a&gt; that there’s a groovy new kid on the &lt;a href="http://en.wikipedia.org/wiki/Template_processor" target="_blank"&gt;template engine&lt;/a&gt; block – &lt;a href="http://channel9.msdn.com/Shows/Going+Deep/Andrew-Nurse-Inside-Razor" target="_blank"&gt;Razor&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;A few customers have been asking folks on both teams some questions around this, such as the following.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Why do you have two engines? &lt;/li&gt;    &lt;li&gt;&lt;a href="http://twitter.com/#!/yzorg/status/26131090053795840" target="_blank"&gt;When should I use each of these two engines&lt;/a&gt;? &lt;/li&gt;    &lt;li&gt;When can I expect &amp;lt;feature X&amp;gt; from one engine to appear in the other one? &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So the T4 and Razor teams got ourselves together in a room and came up with a common way to express how we think about some of these things. Here’s what we came up with:&lt;/p&gt;  &lt;div align="center"&gt;   &lt;table border="0" cellspacing="0" cellpadding="2" width="572" align="center"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="133"&gt;&amp;nbsp;&lt;/td&gt;          &lt;td valign="top" width="133"&gt;&lt;strong&gt;T4&lt;/strong&gt;&lt;/td&gt;          &lt;td valign="top" width="304"&gt;&lt;strong&gt;Razor&lt;/strong&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="133"&gt;Design-time hosting&lt;/td&gt;          &lt;td valign="top" width="133"&gt;Visual Studio &amp;amp; co-installed tools&lt;/td&gt;          &lt;td valign="top" width="304"&gt;Anywhere&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="133"&gt;Runtime options&lt;/td&gt;          &lt;td valign="top" width="133"&gt;Preprocessed templates&lt;/td&gt;          &lt;td valign="top" width="304"&gt;Rehost Razor engine&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="133"&gt;Recommended for generating which file types?&lt;/td&gt;          &lt;td valign="top" width="133"&gt;Not markup&lt;/td&gt;          &lt;td valign="top" width="304"&gt;Markup&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="133"&gt;Optimized for&lt;/td&gt;          &lt;td valign="top" width="133"&gt;Generating arbitrary code assets&lt;/td&gt;          &lt;td valign="top" width="304"&gt;Efficient HTML generation&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="133"&gt;Productivity aids&lt;/td&gt;          &lt;td valign="top" width="133"&gt;&lt;a href="http://www.olegsych.com/2008/02/t4-class-feature-blocks/" target="_blank"&gt;Class feature blocks&amp;#160; (virtual methods)&lt;/a&gt;             &lt;br /&gt;&lt;a href="http://www.olegsych.com/2008/02/t4-include-directive/" target="_blank"&gt;Include directive (template fragment libraries)&lt;/a&gt;&lt;/td&gt;          &lt;td valign="top" width="304"&gt;&lt;a href="http://weblogs.asp.net/mikaelsoderstrom/archive/2010/10/06/declarative-helpers-in-razor.aspx" target="_blank"&gt;Helpers (static standalone code)&lt;/a&gt;             &lt;br /&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx" target="_blank"&gt;Sections (overridable content)&lt;/a&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="133"&gt;Extensibility&lt;/td&gt;          &lt;td valign="top" width="133"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb126315.aspx" target="_blank"&gt;Custom directives&lt;/a&gt;             &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.texttemplating.vshost.itexttemplating.aspx" target="_blank"&gt;VS Service&lt;/a&gt;             &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb126315.aspx" target="_blank"&gt;Custom host&lt;/a&gt;&lt;/td&gt;          &lt;td valign="top" width="304"&gt;Customize or replace most elements of the stack            &lt;br /&gt;&lt;a href="http://blog.andrewnurse.net/2010/11/16/HostingRazorOutsideOfASPNetRevisedForMVC3RC.aspx" target="_blank"&gt;Custom host&lt;/a&gt;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="133"&gt;Editing &lt;/td&gt;          &lt;td valign="top" width="133"&gt;3rd party editors&lt;/td&gt;          &lt;td valign="top" width="304"&gt;VS built-in (HTML output optimized)&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="133"&gt;Core control languages&lt;/td&gt;          &lt;td valign="top" width="133"&gt;C#/VB&lt;/td&gt;          &lt;td valign="top" width="304"&gt;C#/VB&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p align="left"&gt;&amp;#160;&lt;/p&gt;  &lt;p align="left"&gt;In short, we have two engines ‘cos they’re optimized for different use cases.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;div align="left"&gt;Razor uses its implicit knowledge of the type of output it’s generating to allow it to disambiguate control code from output markup and so use a much terser and more pleasing syntax.&lt;/div&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;T4 is designed to generate arbitrary text output, which often means that&amp;#160; the output you’re generating and the control language will be the same; consequently, it has to use more explicit demarcation syntax.&lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p align="left"&gt;We’ll keep adding individual syntax and features that make sense for those separate use cases, but we’ll try and avoid being different at a conceptual level just for the sake of it.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8f74087d-19d5-4ffa-bc1a-4d9add0a7340" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Razor" rel="tag"&gt;Razor&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Template+Engines" rel="tag"&gt;Template Engines&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10139639" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=g-OCw_pJjaQ:FGUKWWRhhH8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Razor/">Razor</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/03/11/t4-vs-razor-what-s-the-skinny.aspx</feedburner:origLink></item><item><title>Scaffold your ASP.NET MVC 3 project with the MvcScaffolding package and customize with T4</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/rDKBXQEqjho/scaffold-your-asp-net-mvc-3-project-with-the-mvcscaffolding-package-and-customize-with-t4.aspx</link><pubDate>Sat, 15 Jan 2011 23:15:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10116206</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10116206</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/01/15/scaffold-your-asp-net-mvc-3-project-with-the-mvcscaffolding-package-and-customize-with-t4.aspx#comments</comments><description>&lt;div class="wlWriterHeaderFooter" style="float:right; margin:0px; padding:0px 0px 4px 8px;"&gt;&lt;script type="text/javascript"&gt;digg_url = "http://blogs.msdn.com/b/garethj/archive/2011/01/15/scaffold-your-asp-net-mvc-3-project-with-the-mvcscaffolding-package-and-customize-with-t4.aspx";digg_title = "Scaffold your ASP.NET MVC 3 project with the MvcScaffolding package and customize with T4";digg_bgcolor = "#FFFFFF";digg_skin = "normal";&lt;/script&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;&lt;/script&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://blog.stevensanderson.com" target="_blank"&gt;Steve Sanderson&lt;/a&gt; has a &lt;a href="http://blog.stevensanderson.com/2011/01/13/scaffold-your-aspnet-mvc-3-project-with-the-mvcscaffolding-package/" target="_blank"&gt;nice post up&lt;/a&gt; about a project he's working on with the estimable &lt;a href="http://www.hanselman.com/blog/" target="_blank"&gt;Scott Hanselman&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;It's a &lt;a href="http://nuget.codeplex.com/" target="_blank"&gt;NuGet&lt;/a&gt; package that provides an even easier&amp;nbsp; on-ramp to development with the just-released &lt;a href="http://www.asp.net/mvc/mvc3" target="_blank"&gt;ASP.NET MVC3&lt;/a&gt; framework.&lt;/p&gt; &lt;p&gt;In their words, it quickly generates a basic outline of your software that you can then edit and customize.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;And even cooler, what it generates can itself be customized by editing&amp;nbsp; a bunch of T4 templates. Sweet!&lt;/p&gt; &lt;p&gt;Check it out by installing the package with &lt;a href="http://nuget.codeplex.com/" target="_blank"&gt;NuGet&lt;/a&gt;: Install-Package MvcScaffolding.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e1c1ecd9-0f26-4e74-a155-615d90eac885" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/ASP.NET" rel="tag"&gt;ASP.NET&lt;/a&gt;,&lt;a href="http://technorati.com/tags/MVC3" rel="tag"&gt;MVC3&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10116206" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=rDKBXQEqjho:lASqlORiw-g:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Enterprise+Development/">Enterprise Development</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/01/15/scaffold-your-asp-net-mvc-3-project-with-the-mvcscaffolding-package-and-customize-with-t4.aspx</feedburner:origLink></item><item><title>VS2010 SP1: T4 Improvements Summary</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/gSHOXPt7PDw/vs2010-sp1-t4-improvements-summary.aspx</link><pubDate>Sat, 15 Jan 2011 00:43:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10116068</guid><dc:creator>GarethJones</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10116068</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/01/15/vs2010-sp1-t4-improvements-summary.aspx#comments</comments><description>&lt;div class="wlWriterHeaderFooter" style="float:right; margin:0px; padding:0px 0px 4px 8px;"&gt;&lt;script type="text/javascript"&gt;digg_url = "http://blogs.msdn.com/b/garethj/archive/2011/01/15/vs2010-sp1-t4-improvements-summary.aspx";digg_title = "VS2010 SP1: T4 Improvements Summary";digg_bgcolor = "#FFFFFF";digg_skin = "normal";&lt;/script&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;&lt;/script&gt;&lt;/div&gt;&lt;p&gt;Over the last few posts, I've talked about the exciting improvements we've made to T4 Text Templating in Service Pack 1 for Visual Studio 2010.&lt;/p&gt; &lt;p&gt;Here's a quick roundup:&lt;/p&gt; &lt;p&gt;Firstly, T4 &lt;a href="http://blogs.msdn.com/b/garethj/archive/2010/12/11/vs2010-sp1-t4-no-longer-locks-assemblies-in-memory.aspx"&gt;no longer locks referenced assemblies in memory&lt;/a&gt;, meaning it's much easier to use reflection in T4 templates and to use compiled helper libraries.&lt;/p&gt; &lt;p&gt;Then I posted a series explaining how to use template inheritance for greater template reuse and easier template customization&lt;/p&gt; &lt;p&gt;In &lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-i-sample-metadata.aspx"&gt;Part I&lt;/a&gt;, I started by setting the scene of why you'd want inheritance and setting up some metadata to drive an example template from.&lt;/p&gt; &lt;p&gt;In &lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-ii-the-core-template.aspx"&gt;Part II&lt;/a&gt;, I put together a T4 preprocessed template that's designed to be reusable and customizable with natural override points.&lt;/p&gt; &lt;p&gt;In &lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-iii-customizing-the-template.aspx"&gt;Part III&lt;/a&gt;, I showed how to exploit the customization points to produce code that's specific to a new project reusing a base template.&lt;/p&gt; &lt;p&gt;In &lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-iv-regular-template-inheritance.aspx"&gt;Part IV&lt;/a&gt;, I wrapped up by showing how to use a helper class to apply the same technique used in preprocessed templates with regular T4 templates.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;I hope you're as excited as we are about these improvements - we really think they make working with T4 a smoother experience.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:99488b50-eb12-454b-8dc9-c5b4e0017d44" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2010+SP1" rel="tag"&gt;Visual Studio 2010 SP1&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10116068" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=gSHOXPt7PDw:H9iTBHNpdZQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Code+samples/">Code samples</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Tech+thrills/">Tech thrills</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Enterprise+Development/">Enterprise Development</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/VSX/">VSX</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/01/15/vs2010-sp1-t4-improvements-summary.aspx</feedburner:origLink></item><item><title>VS2010 SP1: T4 Template Inheritance Part IV – Regular template inheritance</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/MPSuGmW9OOw/vs2010-sp1-t4-template-inheritance-part-iv-regular-template-inheritance.aspx</link><pubDate>Tue, 04 Jan 2011 09:29:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10111399</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10111399</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-iv-regular-template-inheritance.aspx#comments</comments><description>&lt;p&gt;I promised in the &lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-iii-customizing-the-template.aspx"&gt;last post&lt;/a&gt; that I’d show how to do template extensibility and customization using inheritance with regular templates, rather than the preprocessed kind, so here goes.&lt;/p&gt;  &lt;p&gt;The preprocessed solution was a three-layer design.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-36-85-metablogapi/0081.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-36-85-metablogapi/0312.image_5F00_thumb.png" width="353" height="404" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The base preprocessed template, &lt;font face="Courier New"&gt;DataClass.tt&lt;/font&gt; provided the code generation smarts to spit out a customizable C# class from some type description metadata. &lt;/li&gt;    &lt;li&gt;The &lt;font face="Courier New"&gt;Author.tt&lt;/font&gt; and &lt;font face="Courier New"&gt;Book.tt&lt;/font&gt; preprocessed templates provided specializations of this template for metadata instances (for Book and Author in some imaginary library system) and allowed application-level customization. &lt;/li&gt;    &lt;li&gt;Finally the preprocessed templates were used at an application level via simple harness templates, &lt;font face="Courier New"&gt;BookConsumer.tt&lt;/font&gt; and &lt;font face="Courier New"&gt;AuthorConsumer.tt&lt;/font&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;This system works quite well, but it’s a bit clumsy, needing as it does harness templates to call the preprocessed ones and smearing application concepts (Book and Author) across two of its layers.&amp;#160; It would be nice to move to just two layers&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The base layer – provides application-independent template base classes as preprocessed templates &lt;/li&gt;    &lt;li&gt;The application layer – adds application concepts and provides application-wide customizations &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;I scratched my head for a couple of hours and came up with this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-36-85-metablogapi/4520.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-36-85-metablogapi/6278.image_5F00_thumb_5F00_4.png" width="355" height="407" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Much cleaner! So what’s different that’s enabled us to dispense with the intermediate ‘Templates’ project?&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Application-level templates (&lt;font face="Courier New"&gt;Book.tt, Author.tt&lt;/font&gt;) derive directly from &lt;font face="Courier New"&gt;DataClass.tt&lt;/font&gt; preprocessed template class. &lt;/li&gt;    &lt;li&gt;&lt;font face="Courier New"&gt;DataClass.tt&lt;/font&gt; preprocessed template class derives from custom adapter class &lt;font face="Courier New"&gt;TextTransformation.cs&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font face="Courier New"&gt;TextTransformation.cs&lt;/font&gt; derives from T4’s built-in base class &lt;font face="Courier New"&gt;TextTransformation&lt;/font&gt;. &lt;/li&gt;    &lt;li&gt;&lt;font face="Courier New"&gt;BaseTemplates&lt;/font&gt; project references T4’s SDK assembly (You’ll need the &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=396bd827-c6db-4e2d-b5e0-c67857608688" target="_blank"&gt;Visual Studio 2010 SDK&lt;/a&gt; for this variant) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here’s how that inheritance hierarchy looks:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-36-85-metablogapi/3051.image_5F00_14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-36-85-metablogapi/7752.image_5F00_thumb_5F00_6.png" width="647" height="740" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;OK, so that’s all the dirty mechanics; let’s take a look at the new, single-layer application templates:&lt;/p&gt;  &lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;   &lt;div id="codeSnippet" class="csharpcode"&gt;     &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &amp;lt;#@ template debug=&lt;span class="str"&gt;&amp;quot;false&amp;quot;&lt;/span&gt; hostspecific=&lt;span class="str"&gt;&amp;quot;false&amp;quot;&lt;/span&gt; language=&lt;span class="str"&gt;&amp;quot;C#&amp;quot;&lt;/span&gt; inherits=&lt;span class="str"&gt;&amp;quot;BaseTemplates.DataClass&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt; &amp;lt;#@ assembly name=&lt;span class="str"&gt;&amp;quot;$(SolutionDir)\BaseTemplates\$(OutDir)\BaseTemplates.dll&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt; &amp;lt;#@ import &lt;span class="kwrd"&gt;namespace&lt;/span&gt;=&lt;span class="str"&gt;&amp;quot;BaseTemplates&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt; &amp;lt;#@ include file=&lt;span class="str"&gt;&amp;quot;ProjectSpecific.t4&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt; &amp;lt;#@ output extension=&lt;span class="str"&gt;&amp;quot;.cs&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt; &amp;lt;#&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.Description = &lt;span class="kwrd"&gt;new&lt;/span&gt; TypeDescription&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt;                 Name=&lt;span class="str"&gt;&amp;quot;Author&amp;quot;&lt;/span&gt;,  Description=&lt;span class="str"&gt;&amp;quot;A class to carry data about an author in a library system.&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt;                 Properties=&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt;                 {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum12" class="lnum"&gt;  12:&lt;/span&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;ID&amp;quot;&lt;/span&gt;,              Type=&lt;span class="str"&gt;&amp;quot;string&amp;quot;&lt;/span&gt;,    Description=&lt;span class="str"&gt;&amp;quot;The ID of the author.&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum13" class="lnum"&gt;  13:&lt;/span&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;GivenName&amp;quot;&lt;/span&gt;,     Type=&lt;span class="str"&gt;&amp;quot;string&amp;quot;&lt;/span&gt;,    Description=&lt;span class="str"&gt;&amp;quot;The given name of the author.&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum14" class="lnum"&gt;  14:&lt;/span&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;FamilyName&amp;quot;&lt;/span&gt;,    Type=&lt;span class="str"&gt;&amp;quot;string&amp;quot;&lt;/span&gt;,    Description=&lt;span class="str"&gt;&amp;quot;The family name of the author.&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum15" class="lnum"&gt;  15:&lt;/span&gt;                 }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum16" class="lnum"&gt;  16:&lt;/span&gt;             };&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum17" class="lnum"&gt;  17:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum18" class="lnum"&gt;  18:&lt;/span&gt; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; TemplateUse&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum19" class="lnum"&gt;  19:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum20" class="lnum"&gt;  20:&lt;/span&gt;     &lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum21" class="lnum"&gt;  21:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum22" class="lnum"&gt;  22:&lt;/span&gt; &amp;lt;#&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum23" class="lnum"&gt;  23:&lt;/span&gt;     PushIndent();&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum24" class="lnum"&gt;  24:&lt;/span&gt;     &lt;span class="kwrd"&gt;base&lt;/span&gt;.TransformText();&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum25" class="lnum"&gt;  25:&lt;/span&gt;     PopIndent();&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum26" class="lnum"&gt;  26:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum27" class="lnum"&gt;  27:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This is essentially a coalescing of the &lt;font face="Courier New"&gt;Book.tt &lt;/font&gt;and &lt;font face="Courier New"&gt;BookConsumer.tt&lt;/font&gt; templates from the previous version of the solution, but with much less T4 infrastructure on show.&amp;#160; Once again, the project-specific customizations for richer comments and Serialization are included from &lt;font face="Courier New"&gt;ProjectSpecific.t4&lt;/font&gt;, which is unchanged, and all of the application-level code is now in a single, clean layer.&lt;/p&gt;

&lt;p&gt;I think this gives us a really nice pattern now.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Package up your reusable, extensible templates as preprocessed templates in a design-time support library. &lt;/li&gt;

  &lt;li&gt;Use template inheritance from either regular OR preprocessed templates, as your solution demands. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s the updated demo solution :&lt;/p&gt;

&lt;p&gt;&lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-eb5baaa5f2661cf8.office.live.com/embedicon.aspx/.Public/T4InheritanceDemo.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;

&lt;p&gt;For the curious, what’s going on under the hood here?&amp;#160; The key to this variation is that regular T4 templates MUST be derived ultimately from the built-in T4 base class, &lt;font face="Courier New"&gt;Microsoft.VisualStudio.TextTemplating.TextTransformation&lt;/font&gt; (top left in the class diagram).&amp;#160; Preprocessed templates were specifically designed NOT to take a dependency on Visual Studio, so they lift this restriction and instead rely on &lt;a href="http://en.wikipedia.org/wiki/Duck_typing" target="_blank"&gt;duck-typing&lt;/a&gt;.&amp;#160; They simply require a base class with the same set of methods as the built-in one.&lt;/p&gt;

&lt;p&gt;So why can’t &lt;font face="Courier New"&gt;DataClass&lt;/font&gt; inherit directly from the built-in base?&amp;#160; It turns out that the duck-typing match is not exact and in particular, the calls to a utility class, &lt;font face="Courier New"&gt;ToStringHelper,&lt;/font&gt; are instance-based in the case of preprocessed templates and static in the case of regular templates. The adapter class simply reroutes instance-based calls to the static class. With this one little trick, regular templates can inherit from any preprocessed template that in turn inherits from the adapter class.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:fd5eaa99-067a-4af6-bff5-c5f91b0dc46a" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2010+SP1" rel="tag"&gt;Visual Studio 2010 SP1&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10111399" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=MPSuGmW9OOw:meS7_1IgJew:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Code+samples/">Code samples</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/SP1/">SP1</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-iv-regular-template-inheritance.aspx</feedburner:origLink></item><item><title>VS2010 SP1: T4 Template Inheritance Part III – Customizing The Template</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/JzeCiz5q33Y/vs2010-sp1-t4-template-inheritance-part-iii-customizing-the-template.aspx</link><pubDate>Tue, 04 Jan 2011 02:56:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10111317</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10111317</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-iii-customizing-the-template.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-ii-the-core-template.aspx"&gt;Last time, in Part II&lt;/a&gt;, I described a highly structured approach to creating and harnessing a &lt;a href="http://msdn.microsoft.com/en-us/library/ee844259.aspx" target="_blank"&gt;preprocessed template&lt;/a&gt; to generate a simple C# class from metadata. I put lots of nice extensibility points in that template and now we’re going to exploit them to show how easy it gets to be to customize a template once you have such a structure in place.&lt;/p&gt;  &lt;p&gt;Here’s an edited reminder of the code we wanted to generate:&lt;/p&gt;  &lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;   &lt;div id="codeSnippet" class="csharpcode"&gt;     &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt; &lt;span class="rem"&gt;/// A class to carry data about a book in a library system.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt; &lt;span class="rem"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt; &lt;span class="rem"&gt;/// This code generated by the DataClass.tt template - DO NOT MODIFY THIS CODE.&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt; &lt;font style="background-color: #ffff00"&gt;[Serializable]&lt;/font&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;font style="background-color: #ffff00"&gt;internal&lt;/font&gt;&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Book&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt;     &lt;span class="rem"&gt;/// The title of the book.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum12" class="lnum"&gt;  12:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum13" class="lnum"&gt;  13:&lt;/span&gt;     &lt;span class="rem"&gt;&lt;font style="background-color: #ffff00"&gt;/// &amp;lt;remarks&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum14" class="lnum"&gt;  14:&lt;/span&gt;     &lt;span class="rem"&gt;&lt;font style="background-color: #ffff00"&gt;/// This code generated by the DataClass.tt template - DO NOT MODIFY THIS CODE.&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum15" class="lnum"&gt;  15:&lt;/span&gt;     &lt;span class="rem"&gt;&lt;font style="background-color: #ffff00"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum16" class="lnum"&gt;  16:&lt;/span&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Title { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum17" class="lnum"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum18" class="lnum"&gt;  18:&lt;/span&gt;   … More methods elided …&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum41" class="lnum"&gt;  41:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum42" class="lnum"&gt;  42:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We’d like all of the summary comments to contain a reminder not to edit generated code and we need our class to be marked as internal and Serializable.&lt;/p&gt;

&lt;p&gt;If we take a look at the customization points in our base template, &lt;font face="Courier New"&gt;DataClass.tt&lt;/font&gt;, we’ll see we have what we need. We can override &lt;font face="Courier New"&gt;Summary()&lt;/font&gt; and &lt;font face="Courier New"&gt;ClassHeader()&lt;/font&gt; to add the extra text we need:&lt;/p&gt;

&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
  &lt;div id="codeSnippet" class="csharpcode"&gt;
    &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &amp;lt;#+&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt; &lt;span class="rem"&gt;// ---------------------------------------------&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt; &lt;span class="rem"&gt;// Override some of the snippet methods from DataClass.tt to change the template's behavior.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt; &lt;span class="rem"&gt;// ---------------------------------------------&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt; &lt;span class="rem"&gt;/// Override the summary method to remind readers more regularly that this code is auto-generated by a tool&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt;  &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Summary(&lt;span class="kwrd"&gt;string&lt;/span&gt; comment)&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt;     &lt;span class="kwrd"&gt;base&lt;/span&gt;.Summary(comment);&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum12" class="lnum"&gt;  12:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum13" class="lnum"&gt;  13:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum14" class="lnum"&gt;  14:&lt;/span&gt; &lt;span class="rem"&gt;/// This code generated by the DataClass.tt template - DO NOT MODIFY THIS CODE.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum15" class="lnum"&gt;  15:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum16" class="lnum"&gt;  16:&lt;/span&gt; &amp;lt;#+&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum17" class="lnum"&gt;  17:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum18" class="lnum"&gt;  18:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum19" class="lnum"&gt;  19:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum20" class="lnum"&gt;  20:&lt;/span&gt; &lt;span class="rem"&gt;/// Override the class header method to make the generated class partial, internal and Serializable&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum21" class="lnum"&gt;  21:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum22" class="lnum"&gt;  22:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt;  &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ClassHeader(TypeDescription type)&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum23" class="lnum"&gt;  23:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum24" class="lnum"&gt;  24:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum25" class="lnum"&gt;  25:&lt;/span&gt; [Serializable]&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum26" class="lnum"&gt;  26:&lt;/span&gt; &lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; &amp;lt;#= type.Name #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum27" class="lnum"&gt;  27:&lt;/span&gt; &amp;lt;#+ &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum28" class="lnum"&gt;  28:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum29" class="lnum"&gt;  29:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
Note that &lt;font face="Courier New"&gt;Summary()&lt;/font&gt; ‘s override is purely additive, as it calls the base implementation to get the regular summary before adding the extra comment.&amp;#160; By contrast, the override of &lt;font face="Courier New"&gt;ClassHeader()&lt;/font&gt;redefines the output snippet.&amp;#160; It does this as the accessibility of the type isn’t independently customizable without replacing the whole declaration line.&amp;#160; If you keep your output snippets down to a few lines of code at a time, then this kind of thing generally doesn’t compromise maintainability, and means that you don’t need to try and anticipate every last customization need in advance.&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;The next question is, where to put these overrides?&amp;#160; The virtual methods are defined in &lt;font face="Courier New"&gt;DataClass.tt&lt;/font&gt; and then individual template classes derived from that are created in &lt;font face="Courier New"&gt;Book.tt&lt;/font&gt; and &lt;font face="Courier New"&gt;Author.tt&lt;/font&gt; where the specific metadata is defined.&amp;#160; As these would be project-wide customizations, I put them in a separate file, &lt;font face="Courier New"&gt;ProjectSpecific.t4&lt;/font&gt;.&amp;#160; To activate customization, it’s then a simple matter of including that file with a single line in each template class definition.&amp;#160; In the sample I posted as part of &lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-ii-the-core-template.aspx" target="_blank"&gt;Part II&lt;/a&gt;, I only included it in the &lt;font face="Courier New"&gt;Author.tt&lt;/font&gt; file, not &lt;font face="Courier New"&gt;Book.tt&lt;/font&gt; in order to demonstrate the difference in generated code with and without it.&amp;#160; An alternative would have been to put the overrides in an intermediate base class, but that seemed overkill for this sample – either way, there is only a single source for the code.&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;To see the difference with and without, first you regenerate the &lt;font face="Courier New"&gt;Templates&lt;/font&gt; project, to take advantage of template changes, then build that project to compile the precompiled templates.&amp;#160;&amp;#160; Finally regenerate the simple harness templates in the &lt;font face="Courier New"&gt;TemplateUse&lt;/font&gt; project.&amp;#160; You could use the T4/msbuild integration from the &lt;a href="http://code.msdn.microsoft.com/vsvmsdk" target="_blank"&gt;Visualization and Modeling SDK&lt;/a&gt; to automate this process.&amp;#160; To be clear, you don’t need to separate the &lt;font face="Courier New"&gt;Templates&lt;/font&gt; and &lt;font face="Courier New"&gt;BaseTemplates&lt;/font&gt; projects; I just wanted to illustrate the idea of a central repository of templates being customized on a per-project basis.&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;We’ve now seen how to use the new &lt;a href="http://blogs.msdn.com/b/garethj/archive/2010/12/11/vs2010-sp1-t4-no-longer-locks-assemblies-in-memory.aspx" target="_blank"&gt;assembly non-locking&lt;/a&gt; and T4 preprocessed template inheritance features in Visual Studio 2010 SP1 together to set out a clean, structured approach to template reuse and extensibility for medium-scale code generation projects.&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;Can we go further and apply the same techniques to regular T4 templates? I’ll look at that &lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-iv-regular-template-inheritance.aspx"&gt;next time&lt;/a&gt;…&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9fb5f592-b19c-4926-9a5c-764d3e949a46" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2010+SP1" rel="tag"&gt;Visual Studio 2010 SP1&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10111317" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=JzeCiz5q33Y:-hR7FtRvTgg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Code+samples/">Code samples</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/SP1/">SP1</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-iii-customizing-the-template.aspx</feedburner:origLink></item><item><title>VS2010 SP1: T4 Template Inheritance Part II – The Core Template</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/PvhC551M1IY/vs2010-sp1-t4-template-inheritance-part-ii-the-core-template.aspx</link><pubDate>Tue, 04 Jan 2011 02:12:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10111312</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10111312</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-ii-the-core-template.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-i-sample-metadata.aspx"&gt;Last time&lt;/a&gt;, I outlined my scenario – we have a template that produces a very vanilla C# class from metadata and we’d like to customize it to produce something more directly applicable to our current project.&amp;#160; Of course, we could always just copy the standard template into our project and hack around a little until it meets our needs.&amp;#160; With simple templates, that’s often the right thing to do, however once you start to do a lot of code generation, copy/paste reuse just doesn’t cut it and you need some structure.&amp;#160; You can find my complete sample attached to this post.&lt;/p&gt;  &lt;p&gt;&lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-eb5baaa5f2661cf8.office.live.com/embedicon.aspx/.Public/T4PreprocessedInheritance.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;p&gt;The first thing I did was to switch to precompiled templates (introduced in Visual Studio 2010) for my core class-generating template.&amp;#160; A precompiled template gives me a class that you can instantiate and then call the &lt;font face="Courier New"&gt;TransformText()&lt;/font&gt; method on. This method will then produce the same output as a regular template and you can use a simple harness to call it and write the output to disk.&amp;#160; I’m using a regular T4 template as my harness because it’s the easiest way to get a string written to disk as a file in the project system inside Visual Studio.&amp;#160; You can add a preprocessed T4 template from the Visual Studio 2010 Project/Add New Item dialog.&lt;/p&gt;  &lt;p&gt;Here’s the regular harness template, using a preprocessed template class called &lt;font face="Courier New"&gt;Book, generated from a preprocessed template called Book.tt     &lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;       &lt;div id="codeSnippet" class="csharpcode"&gt;         &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &amp;lt;#@ template debug=&lt;span class="str"&gt;&amp;quot;false&amp;quot;&lt;/span&gt; hostspecific=&lt;span class="str"&gt;&amp;quot;false&amp;quot;&lt;/span&gt; language=&lt;span class="str"&gt;&amp;quot;C#&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt; &amp;lt;#@ output extension=&lt;span class="str"&gt;&amp;quot;.cs&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt; &amp;lt;#@ assembly name=&lt;span class="str"&gt;&amp;quot;$(SolutionDir)Templates\$(OutDir)Templates.dll&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt; &amp;lt;#@ assembly name=&lt;span class="str"&gt;&amp;quot;$(SolutionDir)BaseTemplates\$(OutDir)BaseTemplates.dll&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alt"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt; &amp;lt;#@ Import &lt;span class="kwrd"&gt;namespace&lt;/span&gt;=&lt;span class="str"&gt;&amp;quot;Templates&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alteven"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt; &amp;lt;#@ Include File=&lt;span class="str"&gt;&amp;quot;$(SolutionDir)BaseTemplates\Helpers.t4&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; TemplateUse&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt;     &lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt; &amp;lt;#&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt;     var book = &lt;span class="kwrd"&gt;new&lt;/span&gt; Book();&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alteven"&gt;&lt;span id="lnum12" class="lnum"&gt;  12:&lt;/span&gt;     &lt;span class="kwrd"&gt;this&lt;/span&gt;.PushIndent();&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alt"&gt;&lt;span id="lnum13" class="lnum"&gt;  13:&lt;/span&gt;     &lt;span class="kwrd"&gt;this&lt;/span&gt;.WriteLine(book.TransformText());&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alteven"&gt;&lt;span id="lnum14" class="lnum"&gt;  14:&lt;/span&gt;     &lt;span class="kwrd"&gt;this&lt;/span&gt;.PopIndent(); #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

        &lt;pre class="alt"&gt;&lt;span id="lnum15" class="lnum"&gt;  15:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/font&gt;&lt;/p&gt;

&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;I generally put preprocessed templates in a separate project/assembly as you don’t usually want them leaking into your actual application. Here you can see I’ve put them in the Templates and BaseTemplates projects which I’m referring to via VS 2010’s new ability to reference assemblies via project macros such as &lt;font face="Courier New"&gt;$(SolutionDir)&lt;/font&gt;.&amp;#160; This style of working is much, much easier now with Visual Studio 2010 &lt;strong&gt;SP1&lt;/strong&gt;, as &lt;a href="http://blogs.msdn.com/b/garethj/archive/2010/12/11/vs2010-sp1-t4-no-longer-locks-assemblies-in-memory.aspx"&gt;we’ve fixed the assembly locking issues that meant you had to keep restarting your IDE.&lt;/a&gt;&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;I’m using a helper function from my standard function library (Helpers.t4) to make indenting the code a bit more standardized and customizable – I’ll come back to that as a customization point in another post.&amp;#160; The main thrust of this wrapper is that it simply uses &lt;font face="Courier New"&gt;WriteLine()&lt;/font&gt; to spit out the code from the preprocessed template class.&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

&lt;div class="csharpcode-wrapper"&gt;So what’s in the Book class? Let’s have a look at the preprocessed template that generated it:&lt;/div&gt;

&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
  &lt;div id="codeSnippet" class="csharpcode"&gt;
    &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &amp;lt;#@ template debug=&lt;span class="str"&gt;&amp;quot;false&amp;quot;&lt;/span&gt; hostspecific=&lt;span class="str"&gt;&amp;quot;false&amp;quot;&lt;/span&gt; language=&lt;span class="str"&gt;&amp;quot;C#&amp;quot;&lt;/span&gt; inherits=&lt;span class="str"&gt;&amp;quot;BaseTemplates.DataClass&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt; &amp;lt;#@ assembly name=&lt;span class="str"&gt;&amp;quot;$(SolutionDir)\BaseTemplates\bin\debug\BaseTemplates.dll&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt; &amp;lt;#@ import &lt;span class="kwrd"&gt;namespace&lt;/span&gt;=&lt;span class="str"&gt;&amp;quot;BaseTemplates&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt; &amp;lt;#@ output extension=&lt;span class="str"&gt;&amp;quot;.cs&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt; &amp;lt;#&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt; &lt;span class="rem"&gt;// Copyright (C) Microsoft Corporation.  All rights reserved.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.Description = &lt;span class="kwrd"&gt;new&lt;/span&gt; TypeDescription&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt;                 Name=&lt;span class="str"&gt;&amp;quot;Book&amp;quot;&lt;/span&gt;,  Description=&lt;span class="str"&gt;&amp;quot;A class to carry data about a book in a library system.&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt;                 Properties=&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt;                 {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum12" class="lnum"&gt;  12:&lt;/span&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;Title&amp;quot;&lt;/span&gt;,         Type=&lt;span class="str"&gt;&amp;quot;string&amp;quot;&lt;/span&gt;,    Description=&lt;span class="str"&gt;&amp;quot;The title of the book.&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum13" class="lnum"&gt;  13:&lt;/span&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;AuthorID&amp;quot;&lt;/span&gt;,      Type=&lt;span class="str"&gt;&amp;quot;string&amp;quot;&lt;/span&gt;,    Description=&lt;span class="str"&gt;&amp;quot;The ID of the author of the book.&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum14" class="lnum"&gt;  14:&lt;/span&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;ISBN&amp;quot;&lt;/span&gt;,          Type=&lt;span class="str"&gt;&amp;quot;string&amp;quot;&lt;/span&gt;,    Description=&lt;span class="str"&gt;&amp;quot;The standard ISBN number of the book.&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum15" class="lnum"&gt;  15:&lt;/span&gt;                     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;CopiesOwned&amp;quot;&lt;/span&gt;,   Type=&lt;span class="str"&gt;&amp;quot;int&amp;quot;&lt;/span&gt;,       Description=&lt;span class="str"&gt;&amp;quot;The number of copies the library owns.&amp;quot;&lt;/span&gt;}&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum16" class="lnum"&gt;  16:&lt;/span&gt;                 }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum17" class="lnum"&gt;  17:&lt;/span&gt;             };&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum18" class="lnum"&gt;  18:&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.TransformText();&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum19" class="lnum"&gt;  19:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You can see straightaway that this is mostly just the metadata set-up we described last time.&amp;#160; All of the real work is being done in the base template that’s referenced in the &lt;font face="Courier New"&gt;&amp;lt;#@ template inherits=BaseTemplates.DataClass” #&amp;gt;&lt;/font&gt; directive.&amp;#160; That template defines a contract (in the loosest sense of the word) that says you have to set its &lt;font face="Courier New"&gt;Description&lt;/font&gt; property to a piece of metadata before calling the base’s &lt;font face="Courier New"&gt;TransformText()&lt;/font&gt; and it will generate a matching class for you. Here it is:

  &lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
    &lt;div id="codeSnippet" class="csharpcode"&gt;
      &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &amp;lt;#@ template language=&lt;span class="str"&gt;&amp;quot;C#&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt; &amp;lt;#@ import &lt;span class="kwrd"&gt;namespace&lt;/span&gt;=&lt;span class="str"&gt;&amp;quot;System.Collections.Generic&amp;quot;&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt; &amp;lt;#@ include file=&lt;span class="str"&gt;&amp;quot;CSharpHelpers.t4&amp;quot;&lt;/span&gt; #&amp;gt;&amp;lt;#&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt; &lt;span class="rem"&gt;// -----------------------------------------------------------------------------&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt; &lt;span class="rem"&gt;// Template to create a simple C# data carrier class from an instance of datatype description metadata&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt; &lt;span class="rem"&gt;// -----------------------------------------------------------------------------&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;.Description == &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt;     &lt;span class="kwrd"&gt;this&lt;/span&gt;.Error(&lt;span class="str"&gt;&amp;quot;Set the Description property on this template to an instance of the class TypeDescription.&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum12" class="lnum"&gt;  12:&lt;/span&gt; &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum13" class="lnum"&gt;  13:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum14" class="lnum"&gt;  14:&lt;/span&gt;     &lt;span class="rem"&gt;// Define the overall structure of a class.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum15" class="lnum"&gt;  15:&lt;/span&gt;     &lt;span class="rem"&gt;// Generally this should have no template boilerplate in it, so the structure is clear and simple.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum16" class="lnum"&gt;  16:&lt;/span&gt;     Summary(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Description.Description);&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum17" class="lnum"&gt;  17:&lt;/span&gt;     ClassHeader(&lt;span class="kwrd"&gt;this&lt;/span&gt;.Description);&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum18" class="lnum"&gt;  18:&lt;/span&gt;     OpenBrace();&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum19" class="lnum"&gt;  19:&lt;/span&gt;     &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var property &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.Description.Properties) &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum20" class="lnum"&gt;  20:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum21" class="lnum"&gt;  21:&lt;/span&gt;         Property(property);&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum22" class="lnum"&gt;  22:&lt;/span&gt;         NewLine();&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum23" class="lnum"&gt;  23:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum24" class="lnum"&gt;  24:&lt;/span&gt;     CloseBrace();&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum25" class="lnum"&gt;  25:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum26" class="lnum"&gt;  26:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum27" class="lnum"&gt;  27:&lt;/span&gt; &amp;lt;#+ &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum28" class="lnum"&gt;  28:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum29" class="lnum"&gt;  29:&lt;/span&gt; &lt;span class="rem"&gt;// Control properties that drive the template&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum30" class="lnum"&gt;  30:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; TypeDescription Description { get; set; } &lt;span class="rem"&gt;// Description that this template uses.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum31" class="lnum"&gt;  31:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum32" class="lnum"&gt;  32:&lt;/span&gt; &lt;span class="rem"&gt;// -----------------------------------------------------------------------------&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum33" class="lnum"&gt;  33:&lt;/span&gt; &lt;span class="rem"&gt;// Template snippet functions for the individual pieces of a class&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum34" class="lnum"&gt;  34:&lt;/span&gt; &lt;span class="rem"&gt;// Snippets are not indented at all - it is the responsibility of the calling structural method to set correct indenting.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum35" class="lnum"&gt;  35:&lt;/span&gt; &lt;span class="rem"&gt;// -----------------------------------------------------------------------------&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum36" class="lnum"&gt;  36:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum37" class="lnum"&gt;  37:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum38" class="lnum"&gt;  38:&lt;/span&gt; &lt;span class="rem"&gt;/// Generation method to define the template snippet for a summary comment&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum39" class="lnum"&gt;  39:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum40" class="lnum"&gt;  40:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Summary(&lt;span class="kwrd"&gt;string&lt;/span&gt; comment)&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum41" class="lnum"&gt;  41:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum42" class="lnum"&gt;  42:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum43" class="lnum"&gt;  43:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum44" class="lnum"&gt;  44:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;#= comment #&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum45" class="lnum"&gt;  45:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum46" class="lnum"&gt;  46:&lt;/span&gt; &amp;lt;#+ &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum47" class="lnum"&gt;  47:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum48" class="lnum"&gt;  48:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum49" class="lnum"&gt;  49:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum50" class="lnum"&gt;  50:&lt;/span&gt; &lt;span class="rem"&gt;/// Generation method to define the template snippet for a property declaration&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum51" class="lnum"&gt;  51:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum52" class="lnum"&gt;  52:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Property(TypePropertyDescription property)&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum53" class="lnum"&gt;  53:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum54" class="lnum"&gt;  54:&lt;/span&gt;     Summary(property.Description);&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum55" class="lnum"&gt;  55:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum56" class="lnum"&gt;  56:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &amp;lt;#= property.Type #&amp;gt; &amp;lt;#= property.Name #&amp;gt; { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum57" class="lnum"&gt;  57:&lt;/span&gt; &amp;lt;#+ &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum58" class="lnum"&gt;  58:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum59" class="lnum"&gt;  59:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum60" class="lnum"&gt;  60:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum61" class="lnum"&gt;  61:&lt;/span&gt; &lt;span class="rem"&gt;/// Generation method to define the template snippet for the declaration line of a class&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum62" class="lnum"&gt;  62:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum63" class="lnum"&gt;  63:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ClassHeader(TypeDescription type)&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum64" class="lnum"&gt;  64:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum65" class="lnum"&gt;  65:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum66" class="lnum"&gt;  66:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; &amp;lt;#= type.Name #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum67" class="lnum"&gt;  67:&lt;/span&gt; &amp;lt;#+ &lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alteven"&gt;&lt;span id="lnum68" class="lnum"&gt;  68:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;

      &lt;pre class="alt"&gt;&lt;span id="lnum69" class="lnum"&gt;  69:&lt;/span&gt; #&amp;gt;&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
  &lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;The key here is structure. The template has an initial control block that validates its metadata and then defines the logic for generating a class from the metadata provided.&amp;#160; That logic is written as ordinary procedural code and has no template boilerplate in it at all.&amp;#160; I find this separation of core control logic from output text to be key in keeping larger templates maintainable.&amp;#160; The control code uses a few simple helpers (&lt;font face="Courier New"&gt;OpenBrace, CloseBrace, NewLine&lt;/font&gt;) to avoid clumsy &lt;font face="Courier New"&gt;WriteLine&lt;/font&gt; statements and literal strings. This could form the start of a language-agnostic approach to structuring templates, although I’m not going to go down that path here. &lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;The control code then calls out to various methods defined in class feature blocks that write snippets of the output using standard boilerplate syntax. Notice that each of these methods is defined as a virtual method.&amp;#160; Here we have the key to our extensibility story.&amp;#160; We can derive from this template class and replace just the pieces of output generation that we want without disturbing any others or the core logic. In fact, it’s probably a good idea to move that core logic into a virtual method of its own as well so it can be independently customized without disturbing the snippets.&lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;Notice that none of the ouput snippet methods do any indenting – they all assume zero external indentation and leave their callers to manage it.&amp;#160; That way you can build up a library of output methods and mix and match them from different pieces of control logic. You could also break down their parameters to only use simple types so they were independent of specific forms of metadata – it’s a balance between readability and reuse here.&lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;This time, we’ve seen how the core template works to generate vanilla class code in a structured, extensible manner.&amp;#160; &lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-iii-customizing-the-template.aspx"&gt;Next time&lt;/a&gt; we’ll look at taking advantage of that extensibility to create the custom class we asked for in &lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-i-sample-metadata.aspx"&gt;Part I&lt;/a&gt;.&lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:150e871e-cd4b-4d76-8951-62c40dd513e7" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2010+SP1" rel="tag"&gt;Visual Studio 2010 SP1&lt;/a&gt;&lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;

  &lt;div class="csharpcode-wrapper"&gt;&amp;#160;&lt;/div&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10111312" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=PvhC551M1IY:gSZdce02N8Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Code+samples/">Code samples</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/SP1/">SP1</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-ii-the-core-template.aspx</feedburner:origLink></item><item><title>VS2010 SP1: T4 Template Inheritance Part I – Sample Metadata</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/dqH51kNRZZM/vs2010-sp1-t4-template-inheritance-part-i-sample-metadata.aspx</link><pubDate>Tue, 04 Jan 2011 00:48:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10111292</guid><dc:creator>GarethJones</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10111292</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-i-sample-metadata.aspx#comments</comments><description>&lt;p&gt;We’ve done a bunch of work on T4 in Visual Studio 2010 SP1 to enable template inheritance.&amp;#160; &lt;/p&gt;  &lt;p&gt;A reasonable question at this point would be&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;“Why would you want inheritance in your text templates?”&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Well, the typical reason would be the same as with any other code – because you want reuse and extensibility between a family of templates that have some significant similarities.&amp;#160; It’s really nice to be able to customize a template just by overriding a method as you would with any other O-O system.&amp;#160; &lt;a href="http://www.olegsych.com" target="_blank"&gt;Oleg Sych&lt;/a&gt; has an &lt;a href="http://www.olegsych.com/2009/02/t4-tutorial-making-code-generators-extensible/" target="_blank"&gt;example of such a system&lt;/a&gt; on his excellent blog that works well with previous versions of T4 using nested classes, but I like to think the latest version of T4 makes it all a little bit easier.&lt;/p&gt;  &lt;p&gt;I’m going to walk through a couple of examples of using inheritance with a themed sample, so let’s have a look at it.&amp;#160; I’ve &lt;a href="http://blogs.msdn.com/b/garethj/archive/2010/03/11/bending-t4-to-be-a-textual-dsl-host.aspx"&gt;previously discussed&lt;/a&gt; using simple C# data structures to drive a template.&amp;#160; This time I’ve got a couple of classes to provide metadata for simple data structures:&lt;/p&gt;  &lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;   &lt;div id="codeSnippet" class="csharpcode"&gt;     &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TypeDescription&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt;   {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Description { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; List&amp;lt;TypePropertyDescription&amp;gt; Properties =&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt;                  &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;TypePropertyDescription&amp;gt;();&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt;   }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TypePropertyDescription&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt;   {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum12" class="lnum"&gt;  12:&lt;/span&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Type { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum13" class="lnum"&gt;  13:&lt;/span&gt;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Description { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum14" class="lnum"&gt;  14:&lt;/span&gt;   }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;To keep things simple, a type is essentially jus a named and described bunch of properties. You can imagine using something like this to generate C# DAL classes, SQL schema creation scripts, ORM mappings and other typical application paraphernalia.&lt;/p&gt;

&lt;p&gt;Here’s an example of populating the structure:&lt;/p&gt;

&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
  &lt;div id="codeSnippet" class="csharpcode"&gt;
    &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.Description = &lt;span class="kwrd"&gt;new&lt;/span&gt; TypeDescription&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt;   Name=&lt;span class="str"&gt;&amp;quot;Book&amp;quot;&lt;/span&gt;,  Description=&lt;span class="str"&gt;&amp;quot;A class to carry data about a book in a library system.&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt;   Properties=&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt;   {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt;     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;Title&amp;quot;&lt;/span&gt;,         Type=&lt;span class="str"&gt;&amp;quot;string&amp;quot;&lt;/span&gt;,    Description=&lt;span class="str"&gt;&amp;quot;The title of the book.&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt;     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;AuthorID&amp;quot;&lt;/span&gt;,      Type=&lt;span class="str"&gt;&amp;quot;string&amp;quot;&lt;/span&gt;,    Description=&lt;span class="str"&gt;&amp;quot;The ID of the author of the book.&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt;     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;ISBN&amp;quot;&lt;/span&gt;,          Type=&lt;span class="str"&gt;&amp;quot;string&amp;quot;&lt;/span&gt;,    Description=&lt;span class="str"&gt;&amp;quot;The standard ISBN number of the book.&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt;     &lt;span class="kwrd"&gt;new&lt;/span&gt; TypePropertyDescription{Name=&lt;span class="str"&gt;&amp;quot;CopiesOwned&amp;quot;&lt;/span&gt;,   Type=&lt;span class="str"&gt;&amp;quot;int&amp;quot;&lt;/span&gt;,       Description=&lt;span class="str"&gt;&amp;quot;The number of copies the library owns.&amp;quot;&lt;/span&gt;}&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt;   }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt; };&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Let’s say I’m going to generate a simple C# class from this metadata and I have a standard template that generates the following class:&lt;/p&gt;

&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
  &lt;div id="codeSnippet" class="csharpcode"&gt;
    &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt; &lt;span class="rem"&gt;/// A class to carry data about a book in a library system.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Book&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt;     &lt;span class="rem"&gt;/// The title of the book.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Title { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum12" class="lnum"&gt;  12:&lt;/span&gt;     &lt;span class="rem"&gt;/// The ID of the author of the book.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum13" class="lnum"&gt;  13:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum14" class="lnum"&gt;  14:&lt;/span&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; AuthorID { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum15" class="lnum"&gt;  15:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum16" class="lnum"&gt;  16:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum17" class="lnum"&gt;  17:&lt;/span&gt;     &lt;span class="rem"&gt;/// The standard ISBN number of the book.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum18" class="lnum"&gt;  18:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum19" class="lnum"&gt;  19:&lt;/span&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ISBN { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum20" class="lnum"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum21" class="lnum"&gt;  21:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum22" class="lnum"&gt;  22:&lt;/span&gt;     &lt;span class="rem"&gt;/// The number of copies the library owns.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum23" class="lnum"&gt;  23:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum24" class="lnum"&gt;  24:&lt;/span&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; CopiesOwned { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum25" class="lnum"&gt;  25:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum26" class="lnum"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now on a new project, I decide that I need my data class to be serializable and that I want regular reminders not to edit the generated code (people don’t pay a lot of attention to the top of the file as it turns out).&amp;#160; I’d like the following:&lt;/p&gt;

&lt;div id="codeSnippetWrapper" class="csharpcode-wrapper"&gt;
  &lt;div id="codeSnippet" class="csharpcode"&gt;
    &lt;pre class="alt"&gt;&lt;span id="lnum1" class="lnum"&gt;   1:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum2" class="lnum"&gt;   2:&lt;/span&gt; &lt;span class="rem"&gt;/// A class to carry data about a book in a library system.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum3" class="lnum"&gt;   3:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum4" class="lnum"&gt;   4:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum5" class="lnum"&gt;   5:&lt;/span&gt; &lt;span class="rem"&gt;/// This code generated by the DataClass.tt template - DO NOT MODIFY THIS CODE.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum6" class="lnum"&gt;   6:&lt;/span&gt; &lt;span class="rem"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum7" class="lnum"&gt;   7:&lt;/span&gt; [Serializable]&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum8" class="lnum"&gt;   8:&lt;/span&gt; &lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Book&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum9" class="lnum"&gt;   9:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum10" class="lnum"&gt;  10:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum11" class="lnum"&gt;  11:&lt;/span&gt;     &lt;span class="rem"&gt;/// The title of the book.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum12" class="lnum"&gt;  12:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum13" class="lnum"&gt;  13:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum14" class="lnum"&gt;  14:&lt;/span&gt;     &lt;span class="rem"&gt;/// This code generated by the DataClass.tt template - DO NOT MODIFY THIS CODE.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum15" class="lnum"&gt;  15:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum16" class="lnum"&gt;  16:&lt;/span&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Title { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum17" class="lnum"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum18" class="lnum"&gt;  18:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum19" class="lnum"&gt;  19:&lt;/span&gt;     &lt;span class="rem"&gt;/// The ID of the author of the book.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum20" class="lnum"&gt;  20:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum21" class="lnum"&gt;  21:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum22" class="lnum"&gt;  22:&lt;/span&gt;     &lt;span class="rem"&gt;/// This code generated by the DataClass.tt template - DO NOT MODIFY THIS CODE.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum23" class="lnum"&gt;  23:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum24" class="lnum"&gt;  24:&lt;/span&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; AuthorID { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum25" class="lnum"&gt;  25:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum26" class="lnum"&gt;  26:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum27" class="lnum"&gt;  27:&lt;/span&gt;     &lt;span class="rem"&gt;/// The standard ISBN number of the book.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum28" class="lnum"&gt;  28:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum29" class="lnum"&gt;  29:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum30" class="lnum"&gt;  30:&lt;/span&gt;     &lt;span class="rem"&gt;/// This code generated by the DataClass.tt template - DO NOT MODIFY THIS CODE.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum31" class="lnum"&gt;  31:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum32" class="lnum"&gt;  32:&lt;/span&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ISBN { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum33" class="lnum"&gt;  33:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum34" class="lnum"&gt;  34:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum35" class="lnum"&gt;  35:&lt;/span&gt;     &lt;span class="rem"&gt;/// The number of copies the library owns.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum36" class="lnum"&gt;  36:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum37" class="lnum"&gt;  37:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum38" class="lnum"&gt;  38:&lt;/span&gt;     &lt;span class="rem"&gt;/// This code generated by the DataClass.tt template - DO NOT MODIFY THIS CODE.&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum39" class="lnum"&gt;  39:&lt;/span&gt;     &lt;span class="rem"&gt;/// &amp;lt;/remarks&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum40" class="lnum"&gt;  40:&lt;/span&gt;     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; CopiesOwned { get; set; }&lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alt"&gt;&lt;span id="lnum41" class="lnum"&gt;  41:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--crlf--&gt;

    &lt;pre class="alteven"&gt;&lt;span id="lnum42" class="lnum"&gt;  42:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/!--crlf--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-ii-the-core-template.aspx"&gt;Next time&lt;/a&gt;, I’ll show you how to achieve this customization without substantially modifying the original template.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0327baae-248e-43f6-af59-932c7b711d6b" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2010+SP1" rel="tag"&gt;Visual Studio 2010 SP1&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10111292" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=dqH51kNRZZM:15onz3yp2QQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Code+samples/">Code samples</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/SP1/">SP1</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2011/01/04/vs2010-sp1-t4-template-inheritance-part-i-sample-metadata.aspx</feedburner:origLink></item><item><title>VS2010 SP1: T4 no longer locks assemblies in memory</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/ft6zWvLJgcg/vs2010-sp1-t4-no-longer-locks-assemblies-in-memory.aspx</link><pubDate>Sat, 11 Dec 2010 09:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10103559</guid><dc:creator>GarethJones</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10103559</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2010/12/11/vs2010-sp1-t4-no-longer-locks-assemblies-in-memory.aspx#comments</comments><description>&lt;p&gt;I’m pleased to say that we made a few nice improvements to our T4 text templating engine in Visual Studio 2010 SP1 (you can find the beta &lt;a href="http://go.microsoft.com/fwlink/?LinkId=207130" target="_blank"&gt;here&lt;/a&gt;).     &lt;br /&gt;Chief among them is resolving an assembly locking issue that more than a few customers have told us has caused them pain.&lt;/p&gt;  &lt;p&gt;The most typical cases for folks to run across this are:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;when you have a library of code gen helper functions that you want to use from various templates scattered across your solution &lt;/li&gt;    &lt;li&gt;when you’re using reflection inside a template to generate one part of your solution from the output of another part. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The problem manifests when you use the &lt;a href="http://msdn.microsoft.com/en-us/library/bb126421.aspx" target="_blank"&gt;&amp;lt;#@ assembly #&amp;gt; directive&lt;/a&gt; to load one of your assemblies into a template.&amp;#160; You find yourself stuck next time you try to build your solution.&amp;#160; The template has locked that assembly in memory and when you make a change to update a helper, you get a build error as the locked assembly can’t be overwritten.&lt;/p&gt;  &lt;p&gt;In Service Pack 1, we’ve borrowed the ASP.NET assembly shadowing technique, so a temporary copy of your assembly is always loaded rather than the original binary – hey presto, your build should always work now.&lt;/p&gt;  &lt;p&gt;Are there any gotchas?&lt;/p&gt;  &lt;p&gt;For most folks, the shadowing behavior should just work invisibly.&amp;#160; However, if your template happens to take a dependency on the exact physical path of a referenced assembly (perhaps to sneakily load another assembly in a related directory), then you’re going to find a change in behavior.&amp;#160; You’ll now be getting a path somewhere under %TEMP%, which is probably not what you were expecting.&amp;#160; If it’s not convenient to refactor your logic, you can turn off shadowing by setting a value under the following registry key (the Wow6432Node piece is only for 64-bit OSes):&lt;/p&gt;  &lt;p&gt;HKEY_LOCAL_MACHINE\SOFTWARE\[Wow6432Node]\Microsoft\VisualStudio\10.0\TextTemplating&lt;/p&gt;  &lt;p&gt;Set the string value ShadowCopy=false and you’ll be returned to the pre service pack behavior.&lt;/p&gt;  &lt;p&gt;Enjoy…&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:26787b8a-a383-459f-bc99-580bc479da90" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2010+SP1" rel="tag"&gt;Visual Studio 2010 SP1&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Assembly+Locking" rel="tag"&gt;Assembly Locking&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10103559" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=ft6zWvLJgcg:trPCOJimWuI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/VSX/">VSX</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/SP1/">SP1</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2010/12/11/vs2010-sp1-t4-no-longer-locks-assemblies-in-memory.aspx</feedburner:origLink></item><item><title>WCF RIA Services updates T4 Code Generator</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/x1HI-uOR9fk/wcf-ria-services-updates-t4-code-generator.aspx</link><pubDate>Fri, 03 Dec 2010 00:22:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10099775</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10099775</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2010/12/03/wcf-ria-services-updates-t4-code-generator.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As it’s the Silverlight Firestarter event today, the very cool WCF RIA Services team have released a new version of their toolkit.&lt;/p&gt;  &lt;p&gt;You can get the general skinny at &lt;a href="http://jeffhandley.com/archive/2010/12/02/ToolkitDecember2010.aspx"&gt;Jeff Handley’s blog&lt;/a&gt;, but the bit that caught my attention was that they have updated their T4 code generator templates.&lt;/p&gt;  &lt;p&gt;You can get more detail on that at &lt;a href="http://varunpuranik.wordpress.com/2010/12/02/t4-code-generator-dec-10-update/"&gt;Varun Puranik’s&lt;/a&gt; blog.&lt;/p&gt;  &lt;p&gt;Nice.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0a67389b-3dd7-47ea-a447-2b98203ea71e" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/RIA+Services" rel="tag"&gt;RIA Services&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Silverlight" rel="tag"&gt;Silverlight&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10099775" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=x1HI-uOR9fk:verFT3-m_XU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Tech+thrills/">Tech thrills</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Enterprise+Development/">Enterprise Development</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2010/12/03/wcf-ria-services-updates-t4-code-generator.aspx</feedburner:origLink></item><item><title>Maintenance-Free Mocking for Unit Testing with EntityFramework 4.0</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/MoSRBp_0BDA/maintenance-free-mocking-for-unit-testing-with-entityframework-4-0.aspx</link><pubDate>Sat, 21 Aug 2010 05:23:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10052707</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10052707</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2010/08/21/maintenance-free-mocking-for-unit-testing-with-entityframework-4-0.aspx#comments</comments><description>&lt;div class="wlWriterHeaderFooter" style="float:right; margin:0px; padding:0px 0px 4px 8px;"&gt;&lt;script type="text/javascript"&gt;digg_url = "http://blogs.msdn.com/b/garethj/archive/2010/08/21/maintenance-free-mocking-for-unit-testing-with-entityframework-4-0.aspx";digg_title = "Maintenance-Free Mocking for Unit Testing with EntityFramework 4.0";digg_bgcolor = "#FFFFFF";digg_skin = "normal";&lt;/script&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;&lt;/script&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://blogofrab.blogspot.com/" target="_blank"&gt;Rab Hallett&lt;/a&gt; has a nice &lt;a href="http://visualstudiogallery.msdn.microsoft.com/en-us/a850e686-df08-4245-b0bb-5872654285c9" target="_blank"&gt;tool in the VS Gallery&lt;/a&gt; that uses T4 templates to generate mocks for unit-testing EF-based applications&lt;/p&gt; &lt;p&gt;&lt;a title="Maintenance-Free Mocking for Unit Testing with EntityFramework 4.0" href="http://blogofrab.blogspot.com/2010/08/maintenance-free-mocking-for-unit.html"&gt;Maintenance-Free Mocking for Unit Testing with EntityFramework 4.0&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-36-85-metablogapi/7801.object_5F00_context_5F00_interface_5B00_1_5D005F00_2.png" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="object_context_interface[1]" border="0" alt="object_context_interface[1]" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-36-85-metablogapi/4744.object_5F00_context_5F00_interface_5B00_1_5D005F00_thumb.png" width="623" height="389" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e937551b-885e-407c-8df3-f7a4de746e84" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Entity+Framework" rel="tag"&gt;Entity Framework&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Unit+Testing" rel="tag"&gt;Unit Testing&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Mock+Objects" rel="tag"&gt;Mock Objects&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10052707" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=MoSRBp_0BDA:3If9JlfOxCg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Modeling/">Modeling</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Enterprise+Development/">Enterprise Development</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Community/">Community</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2010/08/21/maintenance-free-mocking-for-unit-testing-with-entityframework-4-0.aspx</feedburner:origLink></item><item><title>Visualization and Modeling Feature Pack with T4 Code Generation</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/0afGfNjsX0k/visualization-and-modeling-feature-pack-with-t4-code-generation.aspx</link><pubDate>Tue, 08 Jun 2010 00:26:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10021305</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=10021305</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2010/06/08/visualization-and-modeling-feature-pack-with-t4-code-generation.aspx#comments</comments><description>&lt;p&gt;As &lt;a href="http://blogs.msdn.com/b/jasonz/archive/2010/06/07/announcing-vs2010-productivity-power-tools-and-modeling-feature-packs.aspx"&gt;Jason Zander&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/camerons/archive/2010/06/07/visualization-and-modeling-feature-pack-is-now-available.aspx"&gt;Cameron&lt;/a&gt; have announced, we've just released the first Feature Pack for Visual Studio 2010, the &lt;strong&gt;Visualization and Modeling Feature Pack.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;This pack is available to all MSDN subscribers and among a host of other great features, adds T4-based code generation to our UML static class diagrams.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;img alt="UML class diagram and generated C# class files." src="http://i.msdn.microsoft.com/dynimg/IC402380.png" /&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp; &lt;p&gt;&lt;/p&gt; &lt;p&gt;This add-in works with the C# profile that we shipped with Visual Studio to generate code.&lt;/p&gt; &lt;p&gt;It's a great example of how you can rather easily build a profile yourself to add yet more metadata to your UML model and enrich the code generation further.&lt;/p&gt; &lt;p&gt;You can find all the detail on editing and customizing the templates here: &lt;a title="http://msdn.microsoft.com/library/ff657795.aspx" href="http://msdn.microsoft.com/library/ff657795.aspx"&gt;http://msdn.microsoft.com/library/ff657795.aspx&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Enjoy.&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:12cea08f-2bf0-4d74-a020-1bd45f872269" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Visual+Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;,&lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/UML" rel="tag"&gt;UML&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Code+Generation" rel="tag"&gt;Code Generation&lt;/a&gt;&lt;/div&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10021305" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=0afGfNjsX0k:LJi71seY45Y:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Tech+thrills/">Tech thrills</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Enterprise+Development/">Enterprise Development</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/VSX/">VSX</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/UML/">UML</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Visual+Studio/">Visual Studio</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2010/06/08/visualization-and-modeling-feature-pack-with-t4-code-generation.aspx</feedburner:origLink></item><item><title>What's new in T4 in Visual Studio 2010</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/pmvHyVT2A_8/what-s-new-in-t4-in-visual-studio-2010.aspx</link><pubDate>Thu, 15 Apr 2010 08:54:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9996390</guid><dc:creator>GarethJones</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=9996390</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2010/04/15/what-s-new-in-t4-in-visual-studio-2010.aspx#comments</comments><description>&lt;div class="wlWriterHeaderFooter" style="float:right; margin:0px; padding:0px 0px 4px 8px;"&gt;&lt;script type="text/javascript"&gt;digg_url = "http://blogs.msdn.com/garethj/archive/2010/04/15/what-s-new-in-t4-in-visual-studio-2010.aspx";digg_title = "What's new in T4 in Visual Studio 2010";digg_bgcolor = "#FFFFFF";digg_skin = "normal";&lt;/script&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;&lt;/script&gt;&lt;/div&gt;&lt;p&gt;OK, Visual Studio 2010 is well and truly released, so I thought I'd better catalog what goodness is in the box for all you T4 fans out there..&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;For template authors:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Preprocessed templates to allow embedding of template-based generation in arbitrary applications without a runtime T4 dependency. There is a new custom tool, new service APIs and new engine APIs to support this feature.  &lt;li&gt;Runtime error handling is improved, with better handling of null expression blocks and fewer exceptions being eaten.  &lt;li&gt;Include directives and Assembly directives now support both Windows environment variables and VS Macro variables.  &lt;li&gt;Include directives and Assembly directives now resolved from VSIX Visual Studio extensions downloaded from VS gallery.  &lt;li&gt;Include directives are now also resolved relative to the file that they are declared in to support libraries with relative includes.  &lt;li&gt;Templates always use C#/VB 4.0 and .Net 4.0 types - language version is no longer needed.  &lt;li&gt;Project/Add item templates for C# and VB and Web projects for both regular and preprocessed templates.  &lt;li&gt;T4 now works in Web Site projects.  &lt;li&gt;Generate All Files only runs the T4 custom tools in your project, not arbitrary ones like WPF.  &lt;li&gt;The service tag project stamp is no longer written willy-nilly by T4.  &lt;li&gt;New CompilerOptions flag to the template directive allows arbitrary flags to be sent to the template compiler, allowing optionstrict, optioninfer, optionexplicit etc. to be set for VB.  &lt;li&gt;VS's Custom Tool Namespace is available in CallContext with the tag "NamespaceHint".  &lt;li&gt;Templates no longer support the neutral culture, rather they always go to the invariant culture.  &lt;li&gt;T4-MsBuild to transform your templates at build time.  &lt;li&gt;The parser requires that templates with a class feature block finish with a class feature block to avoid boilerplate write statements hanging free at the end of the class causing hard-to-debug errors.  &lt;li&gt;T4's assembly set is completely separated from the containing project's assembly set to avoid picking up the wrong assemblies when a project targets previous framework versions. Project assemblies are no longer used to resolve template assembly directives.  &lt;li&gt;Assembly references will resolve from Visual Studio's PublicAssemblies folder.  &lt;li&gt;WindowsBase.dll automatically referenced from templates.  &lt;li&gt;Ability to use VS MEF components in the T4 AppDomain - also new CompositionServices helper class to make setting this up simple.  &lt;li&gt;The options page is fully localized.  &lt;li&gt;Better error messages when templates are included from internet zones or downloaded templates are included.  &lt;li&gt;The Generate All Files button is disabled while a build is in progress so there aren't any clashes.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;For custom tool builders:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Hosts can implement ITextTemplatingSessionHost to signal to the engine that they can provide a dictionary of arbitrary user data for the lifetime of the processing session. The data is accessed via a new Session property on the TextTransformation base class.  &lt;li&gt;The built-in VS host implements ITextTemplatingSessionHost and provides a default session implementation to pass data from custom tools into templates while they run in the secondary appdomain, including resolving any necessary assemblies.  &lt;li&gt;New "Parameter" directive with Name and Type properties, similar to the one in the GAX host. This allows custom tools to pass data to templates in a standard way.&amp;nbsp; It resolves from the Session dictionary, the Host via ResolveParameterValue or the CallContext.  &lt;li&gt;T4 interfaces have been split out into a separate assembly to facilitate longer term versioning without taking a dependency on T4's implementation assemblies.  &lt;li&gt;RequiresProvidesDirectiveProcessor uses a new order for processing required parameters to support richer overriding.  &lt;li&gt;BaseCodeGeneratorWithSite now exposes both GlobalServiceProvider and SiteServiceProvider members.  &lt;li&gt;New base class BaseTemplatedCodeGenerator makes it even simpler to create a T4-based custom tool with one override.  &lt;li&gt;ProvideCodeGeneratorExtension attribute makes it easy to hook up custom tools to the web site project system.  &lt;li&gt;Public access to the CacheAssembliesOptionsString in the Engine class to help control caching without magic strings.  &lt;li&gt;Directive Processors support IRecognizeHostSpecific interface to participate in decisions around forcing this flag on.  &lt;li&gt;The correct system implementation of IVsSingleFileGenerator is used rather than a T4 internal one.  &lt;li&gt;Access to the internals of the Visual Studio built-in host via ITextTemplatingComponents service interface.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;For DSL Tools users:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;ModelBus support in templates.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Phew, that's a long list - you can see that Visual Studio 2010 is a big release for T4.&lt;/p&gt; &lt;p&gt;I'll come back and edit this post to include live links as I fill in more details about some of these topics.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d5881c26-19c5-4457-895f-c315f4c7b16e" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2010" rel="tag"&gt;Visual Studio 2010&lt;/a&gt;,&lt;a href="http://technorati.com/tags/What's+New" rel="tag"&gt;What's New&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Text+Templating" rel="tag"&gt;Text Templating&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9996390" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=pmvHyVT2A_8:DejtVTPdNrc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Tech+thrills/">Tech thrills</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2010/04/15/what-s-new-in-t4-in-visual-studio-2010.aspx</feedburner:origLink></item><item><title>Oleg on T4-MSBuild Integration</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/LLnk_TcGWuM/oleg-on-t4-msbuild-integration.aspx</link><pubDate>Wed, 14 Apr 2010 07:28:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9995648</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=9995648</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2010/04/14/oleg-on-t4-msbuild-integration.aspx#comments</comments><description>&lt;div class="wlWriterHeaderFooter" style="float:right; margin:0px; padding:0px 0px 4px 8px;"&gt;&lt;script type="text/javascript"&gt;digg_url = "http://blogs.msdn.com/garethj/archive/2010/04/14/oleg-on-t4-msbuild-integration.aspx";digg_title = "Oleg on T4-MSBuild Integration";digg_bgcolor = "#FFFFFF";digg_skin = "normal";&lt;/script&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;&lt;/script&gt;&lt;/div&gt;&lt;p&gt;The newly released &lt;a href="http://code.msdn.microsoft.com/vsvmsdk" target="_blank"&gt;Visualization and Modeling SDK for Visual Studio 2010&lt;/a&gt; includes support for integrating T4 with msbuild. (yay!)&lt;/p&gt; &lt;p&gt;The ever-diligent &lt;a href="http://www.olegsych.com" target="_blank"&gt;Oleg Sych&lt;/a&gt; has the &lt;a href="http://www.olegsych.com/2010/04/understanding-t4-msbuild-integration/" target="_blank"&gt;full skinny here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:312a6b90-6d0d-470e-aea3-0daa1e117368" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/msbuild" rel="tag"&gt;msbuild&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2010" rel="tag"&gt;Visual Studio 2010&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9995648" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=LLnk_TcGWuM:v1qFajIVSGI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Enterprise+Development/">Enterprise Development</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Community/">Community</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2010/04/14/oleg-on-t4-msbuild-integration.aspx</feedburner:origLink></item><item><title>Bending T4 to be a textual DSL host</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/DYC0jv8GO2g/bending-t4-to-be-a-textual-dsl-host.aspx</link><pubDate>Thu, 11 Mar 2010 10:10:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9976748</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=9976748</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2010/03/11/bending-t4-to-be-a-textual-dsl-host.aspx#comments</comments><description>&lt;div class="wlWriterHeaderFooter" style="float:right; margin:0px; padding:0px 0px 4px 8px;"&gt;&lt;script type="text/javascript"&gt;digg_url = "http://blogs.msdn.com/garethj/archive/2010/03/11/bending-t4-to-be-a-textual-dsl-host.aspx";digg_title = "Bending T4 to be a textual DSL host";digg_bgcolor = "#FFFFFF";digg_skin = "normal";&lt;/script&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;&lt;/script&gt;&lt;/div&gt;&lt;p&gt;The estimable MVP and T4 enthusiast, &lt;a href="http://msmvps.com/blogs/kathleen/default.aspx" target="_blank"&gt;Kathleen Dollard&lt;/a&gt; has a &lt;a href="http://msmvps.com/blogs/kathleen/archive/2009/12/11/killer-feature-for-vnext-language-embedded-dsl.aspx" target="_blank"&gt;new post&lt;/a&gt; where she's using T4's ability to spit arbitrary text as a host for a textual DSL.&lt;/p&gt; &lt;p&gt;She's set up a small DSL for describing contract interfaces for a MEF framework:&lt;/p&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;         &lt;span class="kwrd"&gt;new&lt;/span&gt; Interface()&lt;/pre&gt;&lt;pre&gt;         {&lt;/pre&gt;&lt;pre class="alt"&gt;            Name = &lt;span class="str"&gt;"ISearchModelBase"&lt;/span&gt;,&lt;/pre&gt;&lt;pre&gt;            Scope = Scope.Public,&lt;/pre&gt;&lt;pre class="alt"&gt;            CompositionInfo =&lt;/pre&gt;&lt;pre&gt;            {&lt;/pre&gt;&lt;pre class="alt"&gt;               &lt;span class="kwrd"&gt;new&lt;/span&gt; Property() {Name=&lt;span class="str"&gt;"TargetType"&lt;/span&gt;, PropertyType=&lt;span class="str"&gt;"Type"&lt;/span&gt;}&lt;/pre&gt;&lt;pre&gt;            },&lt;/pre&gt;&lt;pre class="alt"&gt;            Members =&lt;/pre&gt;&lt;pre&gt;            {&lt;/pre&gt;&lt;pre class="alt"&gt;               &lt;span class="kwrd"&gt;new&lt;/span&gt; Property() {Name=&lt;span class="str"&gt;"DisplayName"&lt;/span&gt;, PropertyType=&lt;span class="str"&gt;"string"&lt;/span&gt;},&lt;/pre&gt;&lt;pre&gt;               &lt;span class="kwrd"&gt;new&lt;/span&gt; Property() {Name=&lt;span class="str"&gt;"DataName"&lt;/span&gt;, PropertyType=&lt;span class="str"&gt;"string"&lt;/span&gt;}&lt;/pre&gt;&lt;pre class="alt"&gt;            }&lt;/pre&gt;&lt;pre&gt;         }.Output() &lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Hosting this in T4 with a couple of lines of wrapper code spits out the following output, codifying her standard implementation pattern for MEF contracts and custom attributes:
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;Option&lt;/span&gt; Strict &lt;span class="kwrd"&gt;On&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;Option&lt;/span&gt; Explicit &lt;span class="kwrd"&gt;On&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;Option&lt;/span&gt; Infer &lt;span class="kwrd"&gt;On&lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Collections.Generic&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Linq&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.ComponentModel.Composition &lt;/pre&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;Interface&lt;/span&gt; ISearchModelBase&lt;/pre&gt;&lt;pre class="alt"&gt;   &lt;span class="kwrd"&gt;Property&lt;/span&gt; DisplayName &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;   &lt;span class="kwrd"&gt;Property&lt;/span&gt; DataName &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Interface&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;Interface&lt;/span&gt; ISearchModelBaseComposition&lt;/pre&gt;&lt;pre class="alt"&gt;   &lt;span class="kwrd"&gt;Readonly&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; TargetType &lt;span class="kwrd"&gt;As&lt;/span&gt; Type&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Interface&lt;/span&gt; &lt;/pre&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&amp;lt; MetadataAttribute() &amp;gt; _&lt;/pre&gt;&lt;pre class="alt"&gt;&amp;lt; AttributeUsage(AttributeTargets.&lt;span class="kwrd"&gt;Class&lt;/span&gt;, AllowMultiple:=&lt;span class="kwrd"&gt;False&lt;/span&gt;) &amp;gt; _&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; SearchModelBaseAttribute&lt;/pre&gt;&lt;pre class="alt"&gt;   &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; ExportAttribute&lt;/pre&gt;&lt;pre&gt;   &lt;span class="kwrd"&gt;Implements&lt;/span&gt; ISearchModelBaseComposition &lt;/pre&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;   &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt;( &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; targetType &lt;span class="kwrd"&gt;As&lt;/span&gt; Type)&lt;/pre&gt;&lt;pre class="alt"&gt;      &lt;span class="kwrd"&gt;MyBase&lt;/span&gt;.&lt;span class="kwrd"&gt;New&lt;/span&gt;(&lt;span class="kwrd"&gt;GetType&lt;/span&gt;(ISearchModelBase))&lt;/pre&gt;&lt;pre&gt;      _targetType = targetType&lt;/pre&gt;&lt;pre class="alt"&gt;   &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="alt"&gt;   &lt;span class="kwrd"&gt;Private&lt;/span&gt; _targetType &lt;span class="kwrd"&gt;As&lt;/span&gt; Type&lt;/pre&gt;&lt;pre&gt;   &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Readonly&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; TargetType &lt;span class="kwrd"&gt;As&lt;/span&gt; Type &lt;span class="kwrd"&gt;Implements&lt;/span&gt; ISearchModelBaseComposition.TargetType&lt;/pre&gt;&lt;pre class="alt"&gt;      &lt;span class="kwrd"&gt;Get&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;         &lt;span class="kwrd"&gt;Return&lt;/span&gt; _targetType&lt;/pre&gt;&lt;pre class="alt"&gt;      &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;   &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; &lt;/pre&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; &lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&amp;nbsp; &lt;p&gt;Fascinating stuff, especially when you see that these days, populating such a structure in C#4.0 is such a snap with the new initializer syntax.
&lt;p&gt;Peeking under the covers, at the attachment to Kathleen's blog entry, the code combines the DSL structure definition with the code output for VB in a way that's a bit too printf-ish for my personal taste, so I was tempted to T4 it up a bit.
&lt;p&gt;The original template passes a StringBuilder down the call tree and builds code using AppendLine():
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AppendOpen(System.Text.StringBuilder sb)&lt;/pre&gt;&lt;pre&gt;      {&lt;/pre&gt;&lt;pre class="alt"&gt;         sb.AppendLine(&lt;span class="str"&gt;"Option Strict On"&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;         sb.AppendLine(&lt;span class="str"&gt;"Option Explicit On"&lt;/span&gt;);&lt;/pre&gt;&lt;pre class="alt"&gt;         sb.AppendLine(&lt;span class="str"&gt;"Option Infer On"&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;         sb.AppendLine(&lt;span class="str"&gt;""&lt;/span&gt;);&lt;/pre&gt;&lt;pre class="alt"&gt;         sb.AppendLine(&lt;span class="str"&gt;"Imports System"&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;         sb.AppendLine(&lt;span class="str"&gt;"Imports System.Collections.Generic"&lt;/span&gt;);&lt;/pre&gt;&lt;pre class="alt"&gt;         sb.AppendLine(&lt;span class="str"&gt;"Imports System.Linq"&lt;/span&gt;);&lt;/pre&gt;&lt;pre&gt;         sb.AppendLine(&lt;span class="str"&gt;"Imports System.ComponentModel.Composition"&lt;/span&gt;);&lt;/pre&gt;&lt;pre class="alt"&gt;      }&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
Instead of this, I wanted to use regular T4 syntax with a class feature block:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;      &lt;span class="kwrd"&gt;private&lt;/span&gt; void AppendOpen()&lt;/pre&gt;&lt;pre&gt;      {&lt;/pre&gt;&lt;pre class="alt"&gt;#&amp;gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;Option&lt;/span&gt; Strict &lt;span class="kwrd"&gt;On&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;Option&lt;/span&gt; Explicit &lt;span class="kwrd"&gt;On&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;Option&lt;/span&gt; Infer &lt;span class="kwrd"&gt;On&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Collections.Generic&lt;/pre&gt;&lt;pre&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.Linq&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;Imports&lt;/span&gt; System.ComponentModel.Composition&lt;/pre&gt;&lt;pre&gt;&amp;lt;#+&lt;/pre&gt;&lt;pre class="alt"&gt;      }&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;However, this code is inside a nested class, so the underlying Write statements needed by T4 aren't present.&amp;nbsp; To get around this, I whipped up a trivial base class that supplies all of the necessary plumbing for T4 to be happy.&amp;nbsp;&amp;nbsp; This works because this part of T4 doesn't rely on a specific type, rather it just expects access to the members it needs and any class will do.&amp;nbsp; In my implementation I simply delegate all of the calls back out to the main T4 template.&lt;/p&gt;
&lt;p&gt;The only changes necessary to the DSL definition classes are to derive from my DslBase class and to add a trivial constructor to supply the main template to each DSL class instantiation:&lt;/p&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Interface : DslBase&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Interface(Microsoft.VisualStudio.TextTemplating.TextTransformation outer) : &lt;span class="kwrd"&gt;base&lt;/span&gt;(outer)&lt;/pre&gt;&lt;pre&gt;    {&lt;/pre&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;/div&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I've attached the base class code and a modified version of Kathleen's template for you to play with here. Enjoy.&lt;/p&gt;
&lt;iframe title="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="http://cid-eb5baaa5f2661cf8.skydrive.live.com/embedicon.aspx/.Public/DslBase.zip"&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:10e8e757-710a-40e9-9ab7-b66897691452" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Textual+DSL" rel="tag"&gt;Textual DSL&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9976748" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=DYC0jv8GO2g:7l3oSpoHuQw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Code+samples/">Code samples</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Tech+thrills/">Tech thrills</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Community/">Community</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2010/03/11/bending-t4-to-be-a-textual-dsl-host.aspx</feedburner:origLink></item><item><title>Peter on UML Tools Extensibility</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/KnQciaaR0HM/peter-on-uml-tools-extensibility.aspx</link><pubDate>Tue, 27 Oct 2009 18:56:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9913635</guid><dc:creator>GarethJones</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=9913635</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2009/10/27/peter-on-uml-tools-extensibility.aspx#comments</comments><description>&lt;p&gt;My esteemed colleague &lt;a href="http://www.peterprovost.org/blog" target="_blank"&gt;Peter Provost&lt;/a&gt; – whom I consistently fail to convince that I’m not into process engineering ;-) - has the first in what I’m sure will be a very informative series on &lt;a href="http://www.peterprovost.org/blog/post/Extending-Visual-Studio-2010-UML-Designers-ndash3b-Part-1-Getting-Started.aspx" target="_blank"&gt;extending the UML designers in Visual Studio 2010 Ultimate Edition&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:1aa7f8b0-729b-4684-a4d6-10a1254847c4" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/UML" rel="tag"&gt;UML&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2010" rel="tag"&gt;Visual Studio 2010&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Ultimate+Edition" rel="tag"&gt;Ultimate Edition&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9913635" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=KnQciaaR0HM:xZTBemkOs9s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Modeling/">Modeling</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Enterprise+Development/">Enterprise Development</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/UML/">UML</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2009/10/27/peter-on-uml-tools-extensibility.aspx</feedburner:origLink></item><item><title>DTE and T4 - Better Together</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/Vku7x8YAGb8/dte-and-t4-better-together.aspx</link><pubDate>Fri, 25 Sep 2009 21:27:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9899638</guid><dc:creator>GarethJones</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=9899638</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2009/09/25/dte-and-t4-better-together.aspx#comments</comments><description>&lt;p&gt;A couple of folks out there have put together some really neat T4 templates that use the host-specific flag and then access Visual Studio's DTE object model to read state from other code in the project and use that as metadata for code generation.&lt;/p&gt; &lt;p&gt;&lt;a href="http://danielvaughan.orpius.com" target="_blank"&gt;Daniel Vaughan&lt;/a&gt; started out with &lt;a href="http://danielvaughan.orpius.com/post/MetaGen-A-project-metadata-generator-for-Visual-Studio-using-T4.aspx" target="_blank"&gt;a&amp;nbsp; nice post&lt;/a&gt; on using DTE to explore the source constructs within your project using the CodeModel and thence using that data to&amp;nbsp; introduce compile time strong-typing to WPF binding expressions.&lt;/p&gt; &lt;p&gt;To borrow Daniel's example, to switch from this weakly typed case&lt;/p&gt; &lt;blockquote&gt;&lt;pre&gt;&amp;lt;StackPanel DataContext="{Binding Source={StaticResource Person}}"&amp;gt;
    &amp;lt;TextBlock &amp;gt;Name:&amp;lt;/TextBlock&amp;gt;
    &amp;lt;TextBox Text="{Binding Name}" /&amp;gt;
&amp;lt;/StackPanel&amp;gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;to this strongly typed one which gives compile-time errors if you get the name wrong&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;StackPanel DataContext="{Binding Source={StaticResource Person}}"&amp;gt;
	&amp;lt;TextBlock &amp;gt;Name:&amp;lt;/TextBlock&amp;gt;
	&amp;lt;TextBox Text="{Binding Path={x:Static Metadata:PersonMetadata.NamePath}}"/&amp;gt;
&amp;lt;/StackPanel&amp;gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;He then also talks about using the same technique to generate implementations of &lt;em&gt;INotifyPropertyChange&lt;/em&gt; that are robust to refactoring without the problems of embedded strings or the performance hit of reflection.&amp;nbsp; Code generation and declarative programming are often criticized for not having good support for refactoring, so it's nice to see a use case that actually helps support refactoring.&lt;/p&gt;
&lt;p&gt;Daniel has now expanded this into a &lt;a href="http://www.codeproject.com/KB/codegen/T4Metadata.aspx" target="_blank"&gt;full article on The Code Project&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Last time, I talked about &lt;a href="http://www.codeproject.com/KB/WPF/DependencyPropertyCodeGen.aspx" target="_blank"&gt;Colin Eberhardt's article&lt;/a&gt; for generating Dependency Properties from an xml file.&amp;nbsp; Daniel's approach inspired Colin to go back and &lt;a href="http://www.scottlogic.co.uk/blog/wpf/2009/08/declarative-dependency-property-definition-with-t4-dte/" target="_blank"&gt;rework his example to use DTE&lt;/a&gt; replacing his external XML file with custom attributes on classes to simply add dependency properties like so:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;[DependencyPropertyDecl("Maximum", typeof(double), 0.0)]
[DependencyPropertyDecl("Minimum", typeof(double), 0.0)]
public partial class RangeControl : UserControl
{
    ...
}&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;Very cool stuff.&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7a206d04-630a-42bf-8514-2b5863c4b6f5" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/DTE" rel="tag"&gt;DTE&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2008" rel="tag"&gt;Visual Studio 2008&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Code+Generation" rel="tag"&gt;Code Generation&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Dependecy+Property" rel="tag"&gt;Dependecy Property&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Databinding" rel="tag"&gt;Databinding&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Strongly-typed" rel="tag"&gt;Strongly-typed&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9899638" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=Vku7x8YAGb8:KKeDcP7fzSE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Tech+thrills/">Tech thrills</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Enterprise+Development/">Enterprise Development</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Community/">Community</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2009/09/25/dte-and-t4-better-together.aspx</feedburner:origLink></item><item><title>T4 and Silverlight in Visual Studio 2008</title><link>http://feedproxy.google.com/~r/GarethjsWeblog/~3/OT9uPLCbdMc/t4-and-silverlight-in-visual-studio-2008.aspx</link><pubDate>Fri, 25 Sep 2009 20:32:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9899609</guid><dc:creator>GarethJones</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.msdn.com/b/garethj/rsscomments.aspx?WeblogPostID=9899609</wfw:commentRss><comments>http://blogs.msdn.com/b/garethj/archive/2009/09/25/t4-and-silverlight-in-visual-studio-2008.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.scottlogic.co.uk/blog/wpf/" target="_blank"&gt;Colin Eberhardt&lt;/a&gt; has a nice article on &lt;a href="http://www.codeproject.com" target="_blank"&gt;The Code Project&lt;/a&gt; walking through using a small textual DSL encoded in XML to define a set of dependency properties and then using that as a data source for T4 to generate all of the necessary boilerplate code.&lt;/p&gt; &lt;p&gt;Apart from being intrinsically cool, he's also doing this in a Silverlight project, and he includes the small amount of special sauce needed to get T4 generation working in a Silverlight project inside Visual Studio 2008.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;BTW, in Visual Studio 2010, T4 in Silverlight should "just work".&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6500bc74-c71f-4dea-ac02-9dedb4893e6e" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/T4" rel="tag"&gt;T4&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SIlverlight" rel="tag"&gt;SIlverlight&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Visual+Studio+2008" rel="tag"&gt;Visual Studio 2008&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Dependecy+Property" rel="tag"&gt;Dependecy Property&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9899609" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/GarethjsWeblog?a=OT9uPLCbdMc:hzahJMfmHoM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/GarethjsWeblog?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Enterprise+Development/">Enterprise Development</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/Community/">Community</category><category domain="http://blogs.msdn.com/b/garethj/archive/tags/T4/">T4</category><feedburner:origLink>http://blogs.msdn.com/b/garethj/archive/2009/09/25/t4-and-silverlight-in-visual-studio-2008.aspx</feedburner:origLink></item></channel></rss>
