开发者

How do you display the code (not output) that .Net T4 generates?

We have a set of T4 templates we have just mig开发者_如何学Pythonrated forward to VS 2010 and they compile but are no longer working the same.

In order to see what is actually going on under the hood it would be useful to see the temporary cs files that T4 generates to produce the actual T4 conversion.


As you're now using Visual Studio 2010, you can also change the custom tool on the template from TextTemplatingFileGenerator to TextTemplatingFilePreprocessor temporarily.

This will spit out the underlying code directly into your project instead of the regular template output.


If you set

<#@ template  debug="true"#>

then the generated code will be left in your temp directory. On my Windows 7 system, that's C:\Users\John Saunders\AppData\Local\Temp.


I don't know how to do exactly what you want, however I do know how to step through the t4 code in visual studio. You need to start a second instance of visual studio and attach it to the first instance using the Debug->Attach to process... (Attaching it to itself, weird, I know). This then allows you to put breakpoints in the T4 file in your second instance and it will stop and let you step through it and see what is going on.

Edit:

You need to be doing the t4 transform in visual studio instead of the command line tool for this to work. Put your .tt file in to your project and set the "Custom Tool" in its properties to "TextTemplatingFileGenerator". It will generate the files every time you tell the file to save, or when you right click and say "Run Custom Tool" on the file. See this MSDN article for more info.

I also recommend getting the tangible T4 editor the free version adds code highlighting and intellisense to about 90% of the use cases I needed for it (it only adds it for functions in Core.dll for the .NET framework). the pay version will add intellisense to all attached assemblies.

Edit2: If you REALLY want the temporary cs files it uses you can see what cs files from the temporary folder are loaded in the debugger (i don't remember exactly where).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜