<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Understanding T4: &#60;#@ template #&#62; directive</title>
	<link>http://www.olegsych.com/2008/02/t4-template-directive/</link>
	<description>this.Write(code);</description>
	<pubDate>Tue, 18 Nov 2008 15:19:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Mike Baker</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-337</link>
		<dc:creator>Mike Baker</dc:creator>
		<pubDate>Fri, 01 Aug 2008 00:53:59 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-337</guid>
		<description>For what it's worth, I discovered the answer to my original question – how to get VS 2008 to run a template when building (although now I don’t plan to use it as my final solution, per Oleg's advice).

Here’s how to do it:

1. View the properties of the project file (.csproj).

2. Add a pre-build step as follows (for a template called foo.tt):
"C:\Program Files\Common Files\Microsoft Shared\TextTemplating\1.2\TextTransform" -out $(ProjectDir)\foo.cs -I $(ProjectDir) $(ProjectDir)\foo.tt

3. Save and build.

Good luck,
-Mike</description>
		<content:encoded><![CDATA[<p>For what it&#8217;s worth, I discovered the answer to my original question – how to get VS 2008 to run a template when building (although now I don’t plan to use it as my final solution, per Oleg&#8217;s advice).</p>
<p>Here’s how to do it:</p>
<p>1. View the properties of the project file (.csproj).</p>
<p>2. Add a pre-build step as follows (for a template called foo.tt):<br />
&#8220;C:\Program Files\Common Files\Microsoft Shared\TextTemplating\1.2\TextTransform&#8221; -out $(ProjectDir)\foo.cs -I $(ProjectDir) $(ProjectDir)\foo.tt</p>
<p>3. Save and build.</p>
<p>Good luck,<br />
-Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Baker</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-336</link>
		<dc:creator>Mike Baker</dc:creator>
		<pubDate>Thu, 31 Jul 2008 21:02:56 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-336</guid>
		<description>Thanks for the sound advice, Oleg.  

Originally I checked in the generated .cs files so as to not break the build, but given your perspectives, it sounds like it is also the final solution.
-Mike</description>
		<content:encoded><![CDATA[<p>Thanks for the sound advice, Oleg.  </p>
<p>Originally I checked in the generated .cs files so as to not break the build, but given your perspectives, it sounds like it is also the final solution.<br />
-Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oleg Sych</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-335</link>
		<dc:creator>Oleg Sych</dc:creator>
		<pubDate>Thu, 31 Jul 2008 20:28:10 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-335</guid>
		<description>Mike, 

To transform T4 templates during build you could use Elton Stoneman's  &lt;a href="http://geekswithblogs.net/EltonStoneman/archive/2008/07/25/an-msbuild-task-to-execute-t4-templates.aspx" rel="nofollow"&gt;MSBuild task for transforming T4 templates&lt;/a&gt; and customize MSBuild scripts to compile the output files they generate. However, unless you remove TextTemplatingFileGenerator custom tool from .tt file properties, Visual Studio will continue transforming the templates every time you save them.  

I'm not sure this approach is better than code generation at design time only, which is what T4 and other code generation tools in Visual Studio are designed to do. I would be particularly concerned about not having the generated source code stored in source control repository. Because development environment can change, there is no guarantee that you can regenerate the exact same code that was shipped or delivered to production months or years ago. Troubleshooting and debugging in this situation becomes very challenging.

Oleg</description>
		<content:encoded><![CDATA[<p>Mike, </p>
<p>To transform T4 templates during build you could use Elton Stoneman&#8217;s  <a href="http://geekswithblogs.net/EltonStoneman/archive/2008/07/25/an-msbuild-task-to-execute-t4-templates.aspx" rel="nofollow">MSBuild task for transforming T4 templates</a> and customize MSBuild scripts to compile the output files they generate. However, unless you remove TextTemplatingFileGenerator custom tool from .tt file properties, Visual Studio will continue transforming the templates every time you save them.  </p>
<p>I&#8217;m not sure this approach is better than code generation at design time only, which is what T4 and other code generation tools in Visual Studio are designed to do. I would be particularly concerned about not having the generated source code stored in source control repository. Because development environment can change, there is no guarantee that you can regenerate the exact same code that was shipped or delivered to production months or years ago. Troubleshooting and debugging in this situation becomes very challenging.</p>
<p>Oleg</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Baker</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-333</link>
		<dc:creator>Mike Baker</dc:creator>
		<pubDate>Thu, 31 Jul 2008 18:44:28 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-333</guid>
		<description>How do you cause a T4 template to generate its output file upon the VS 2008 solution (.sln) file being built?

There are only two ways of running the template file that I’ve found:
– Right-clicking on the .tt file, and selecting “Run Custom Tool”
– Editing the content of the .tt file seems to automatically run it

I am using ClearCase, and it would seem best to add to source control only the .tt files, not the generated .cs files.

Thanks,
-Mike</description>
		<content:encoded><![CDATA[<p>How do you cause a T4 template to generate its output file upon the VS 2008 solution (.sln) file being built?</p>
<p>There are only two ways of running the template file that I’ve found:<br />
– Right-clicking on the .tt file, and selecting “Run Custom Tool”<br />
– Editing the content of the .tt file seems to automatically run it</p>
<p>I am using ClearCase, and it would seem best to add to source control only the .tt files, not the generated .cs files.</p>
<p>Thanks,<br />
-Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elton</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-300</link>
		<dc:creator>Elton</dc:creator>
		<pubDate>Fri, 25 Jul 2008 13:13:11 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-300</guid>
		<description>Good series on T4 from your blog Oleg - thanks. 

I've put together a simple MSBuild task which executes a T4 template. It lets you reference build properties and item groups in the template and will replace them with the runtime values from MSBuild: 

http://geekswithblogs.net/EltonStoneman/archive/2008/07/25/an-msbuild-task-to-execute-t4-templates.aspx

Elton.</description>
		<content:encoded><![CDATA[<p>Good series on T4 from your blog Oleg - thanks. </p>
<p>I&#8217;ve put together a simple MSBuild task which executes a T4 template. It lets you reference build properties and item groups in the template and will replace them with the runtime values from MSBuild: </p>
<p><a href="http://geekswithblogs.net/EltonStoneman/archive/2008/07/25/an-msbuild-task-to-execute-t4-templates.aspx" rel="nofollow">http://geekswithblogs.net/EltonStoneman/archive/2008/07/25/an-msbuild-task-to-execute-t4-templates.aspx</a></p>
<p>Elton.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Experimental LINQ to SQL template for T4 &#187; DamienG</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-234</link>
		<dc:creator>Experimental LINQ to SQL template for T4 &#187; DamienG</dc:creator>
		<pubDate>Wed, 25 Jun 2008 22:13:01 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-234</guid>
		<description>[...] Checking out Oleg Sych's blog for great T4 articles including how to enable the 3.5 compiler for templates [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Checking out Oleg Sych&#8217;s blog for great T4 articles including how to enable the 3.5 compiler for templates [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Shestakov</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-120</link>
		<dc:creator>Alex Shestakov</dc:creator>
		<pubDate>Tue, 08 Apr 2008 16:53:39 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-120</guid>
		<description>Hi, Oleg!

Sure, I am glad to share the code, though it is dirty yet. In my implementation the only option is to provide the template with the path to the file where it can take settings from.
I have just started my blog at http://blog.alexshestakov.com and in the post coming soon I am going to describe the background of my implementation of the entity engine.

Concerning the transformation host in the VS: I am not sure I like to have my templates rendered every time I save the template source. Actually, rendering of some database schema templates could take very much time. And, what is even more important, I would like to create stand-alone code generators (without an ability to edit a template, but for multiple parameter sets), as in the real world the code generation is usually run because of changes in a parameter set, rather than in a template itself.

I can email you the sources, you may send a request to my email at any time.</description>
		<content:encoded><![CDATA[<p>Hi, Oleg!</p>
<p>Sure, I am glad to share the code, though it is dirty yet. In my implementation the only option is to provide the template with the path to the file where it can take settings from.<br />
I have just started my blog at <a href="http://blog.alexshestakov.com" rel="nofollow">http://blog.alexshestakov.com</a> and in the post coming soon I am going to describe the background of my implementation of the entity engine.</p>
<p>Concerning the transformation host in the VS: I am not sure I like to have my templates rendered every time I save the template source. Actually, rendering of some database schema templates could take very much time. And, what is even more important, I would like to create stand-alone code generators (without an ability to edit a template, but for multiple parameter sets), as in the real world the code generation is usually run because of changes in a parameter set, rather than in a template itself.</p>
<p>I can email you the sources, you may send a request to my email at any time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oleg Sych</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-110</link>
		<dc:creator>Oleg Sych</dc:creator>
		<pubDate>Sun, 06 Apr 2008 13:41:09 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-110</guid>
		<description>Alex, 

That's quite impressive. I would love to see your code and understand better what you are trying to accomplish. I also kept an idea of building a T4 MSBuild task in the back of my mind. Perhaps we could work on this together. Do you have a blog?

About storing template parameter sets... Even though T4 is not as advanced as CodeSmith project file, there are ways to achieve the same results without having to build and deploy any additional tools. For example, in &lt;a href="http://www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/" rel="nofollow"&gt;How to generate multiple outputs from single T4 template&lt;/a&gt; I described two methods of passing parameters to templates. One is using helper method parameters and the other is using CallContext. With either method, the calling template works as an equivalent of a CodeSmith project file. I would be interested in your thoughts on this.</description>
		<content:encoded><![CDATA[<p>Alex, </p>
<p>That&#8217;s quite impressive. I would love to see your code and understand better what you are trying to accomplish. I also kept an idea of building a T4 MSBuild task in the back of my mind. Perhaps we could work on this together. Do you have a blog?</p>
<p>About storing template parameter sets&#8230; Even though T4 is not as advanced as CodeSmith project file, there are ways to achieve the same results without having to build and deploy any additional tools. For example, in <a href="http://www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/" rel="nofollow">How to generate multiple outputs from single T4 template</a> I described two methods of passing parameters to templates. One is using helper method parameters and the other is using CallContext. With either method, the calling template works as an equivalent of a CodeSmith project file. I would be interested in your thoughts on this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Shestakov</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-109</link>
		<dc:creator>Alex Shestakov</dc:creator>
		<pubDate>Sun, 06 Apr 2008 05:40:49 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-109</guid>
		<description>Final results.

Yesterday I have created my custom template host and custom directive to provide parameters to the template renderer. The VS integrated template processing tool is no good as it doesn't contain any way so provide parameters to the renderer. It means that I am to create a file format to store template parameter sets (equivalent of CodeSmith's projects), certain VS project type and MSbuild task to build output scripts for all the setting sets in one template renderer run. It guarantees that the database schema and other metadata will be loaded only once. That's what CodeSmith can't do. Visual Studio also guarantees that the output .dll of the projects containing the basic class we inherit will be placed in the project's output directory. So we can even build a multiple-time usable .exe that will consume parameter file names as the command line args. It seems to be operational... in theory :)</description>
		<content:encoded><![CDATA[<p>Final results.</p>
<p>Yesterday I have created my custom template host and custom directive to provide parameters to the template renderer. The VS integrated template processing tool is no good as it doesn&#8217;t contain any way so provide parameters to the renderer. It means that I am to create a file format to store template parameter sets (equivalent of CodeSmith&#8217;s projects), certain VS project type and MSbuild task to build output scripts for all the setting sets in one template renderer run. It guarantees that the database schema and other metadata will be loaded only once. That&#8217;s what CodeSmith can&#8217;t do. Visual Studio also guarantees that the output .dll of the projects containing the basic class we inherit will be placed in the project&#8217;s output directory. So we can even build a multiple-time usable .exe that will consume parameter file names as the command line args. It seems to be operational&#8230; in theory :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Shestakov</title>
		<link>http://www.olegsych.com/2008/02/t4-template-directive/#comment-105</link>
		<dc:creator>Alex Shestakov</dc:creator>
		<pubDate>Fri, 04 Apr 2008 07:55:40 +0000</pubDate>
		<guid>http://www.olegsych.com/2008/02/t4-template-directive/#comment-105</guid>
		<description>Update:
It was my fault. I didn't add the attribute pointing to the DirectiveProcessor into the directive tag. Now fighting the reference hell.</description>
		<content:encoded><![CDATA[<p>Update:<br />
It was my fault. I didn&#8217;t add the attribute pointing to the DirectiveProcessor into the directive tag. Now fighting the reference hell.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
