<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" 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/"><channel><title>Two ways to use T4 templates: support code vs. one-time generation</title><link>http://blogs.msdn.com/davidebb/archive/2009/07/17/two-ways-to-use-t4-templates-support-code-vs-one-time-generation.aspx</link><description>T4 templates have proven to be useful is a whole range of scenarios, and more and more developers are finding interesting things to do with them. For the most part, all those scenarios fall under two very distinct categories: “support code” versus one-time</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Two ways to use T4 templates: support code vs. one-time generation</title><link>http://blogs.msdn.com/davidebb/archive/2009/07/17/two-ways-to-use-t4-templates-support-code-vs-one-time-generation.aspx#9837179</link><pubDate>Fri, 17 Jul 2009 13:52:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9837179</guid><dc:creator>Harry M</dc:creator><description>&lt;p&gt;I would strongly advise against the 'one-time generation' use, and suggest an alternative.&lt;/p&gt;
&lt;p&gt;One time use results in a whole load of code that you couldn't be bothered to write being generated, which means you now have a load of code you won't be able to maintain. If the generated code needs to change, you can't rerun the script as you'll lose your modifications.&lt;/p&gt;
&lt;p&gt;Instead what you should do is have it generate code that is extensible, rather than requiring modification (like MS do with partial methods in Linq to SQL). &lt;/p&gt;
&lt;p&gt;Even better than that is to improve the cleverness of the generator so that it can generate the necessary tweaks from the input the t4 template takes. &lt;/p&gt;
&lt;p&gt;e.g. if you are generating code by reflecting over an assembly, and one class in particular needs customisation, flag the class with an attribute so the generator can treat it differently. If you don't have control over the assembly, pass an argument to the t4 template.&lt;/p&gt;
</description></item><item><title>re: Two ways to use T4 templates: support code vs. one-time generation</title><link>http://blogs.msdn.com/davidebb/archive/2009/07/17/two-ways-to-use-t4-templates-support-code-vs-one-time-generation.aspx#9837200</link><pubDate>Fri, 17 Jul 2009 13:57:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9837200</guid><dc:creator>Harry M</dc:creator><description>&lt;p&gt;I guess I didn't really suggest an alternative, just the first method, but what I'm trying to get at is that the second shouldn't really ever be used, with the possible exception of views as designers like to tweak the heck out of views (even then I'd rather have a clever convention based generation system to provide truly consistent look n feel). Don't do 1 time generation in code YOU are going to have to maintain.&lt;/p&gt;
</description></item><item><title>re: Two ways to use T4 templates: support code vs. one-time generation</title><link>http://blogs.msdn.com/davidebb/archive/2009/07/17/two-ways-to-use-t4-templates-support-code-vs-one-time-generation.aspx#9837684</link><pubDate>Fri, 17 Jul 2009 20:52:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9837684</guid><dc:creator>davidebb</dc:creator><description>&lt;p&gt;Harry, I don't really agree that one-time generation is necessarily a bad thing, although it can be. It all depends how you look at it.&lt;/p&gt;
&lt;p&gt;If you look at it as a bunch of generated code that you now have to maintain, then indeed it seems bad.&lt;/p&gt;
&lt;p&gt;Instead, you should look at it as a smarter Item Template, then it becomes a good thing. Think of how you create new files in VS using Add / New. Whether it's a code file, aspx file, or just about any file format, VS doesn't give you an empty file. It gives you a starter file containing a C# class or an aspx file with some basic directives and some markup.&lt;/p&gt;
&lt;p&gt;But this 'starter content' is pretty static, and not easily customizable. If you instead use T4 to generate this starter file, you can give smarter much starter/dynamic content, and by customizing the T4 file the user can tailor the starter content to be what they prefer.&lt;/p&gt;
</description></item><item><title>re: Two ways to use T4 templates: support code vs. one-time generation</title><link>http://blogs.msdn.com/davidebb/archive/2009/07/17/two-ways-to-use-t4-templates-support-code-vs-one-time-generation.aspx#9838052</link><pubDate>Sat, 18 Jul 2009 03:21:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9838052</guid><dc:creator>Harsha</dc:creator><description>&lt;p&gt;I use T4 templates in my project to generate teh repeating data-access code from a metadata file and I am loving it. &lt;/p&gt;
</description></item><item><title>re: Two ways to use T4 templates: support code vs. one-time generation</title><link>http://blogs.msdn.com/davidebb/archive/2009/07/17/two-ways-to-use-t4-templates-support-code-vs-one-time-generation.aspx#9838538</link><pubDate>Sat, 18 Jul 2009 14:34:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9838538</guid><dc:creator>sjnaughton</dc:creator><description>&lt;p&gt;Hi David, I like you you code listings is that something new on your msdn blog or a new adding ofr live writer?&lt;/p&gt;
&lt;p&gt;Steve&lt;/p&gt;
</description></item><item><title>re: Two ways to use T4 templates: support code vs. one-time generation</title><link>http://blogs.msdn.com/davidebb/archive/2009/07/17/two-ways-to-use-t4-templates-support-code-vs-one-time-generation.aspx#9841004</link><pubDate>Mon, 20 Jul 2009 09:51:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9841004</guid><dc:creator>davidebb</dc:creator><description>&lt;p&gt;Steve, I switched to using SyntaxHighlighter, per Hanselman's blog: &lt;a rel="nofollow" target="_new" href="http://www.hanselman.com/blog/BestCodeSyntaxHighlighterForSnippetsInYourBlog.aspx"&gt;http://www.hanselman.com/blog/BestCodeSyntaxHighlighterForSnippetsInYourBlog.aspx&lt;/a&gt;. It's a totally different approach to code snippets, as it gets formatted on the fly on the client.&lt;/p&gt;
</description></item></channel></rss>