t4 templates per template TransformOnBuild setting

你离开我真会死。 提交于 2019-12-24 03:50:18

问题


I would like to automatically execute one of the .tt files when my project is built, but not the others. Is it possible to set the TransformOnBuild property on specific .tt files instead of project wide? Or another method to accomplish this?


回答1:


I have decided to add a custom pre build step to generate the .tt files needed:

<Exec Command="&quot;%PROGRAMFILES(x86)%\Common Files\microsoft shared\TextTemplating\10.0\TextTransform.exe&quot; template.tt -out template.cs" />

This method also allowed me to easily pass parameters (defined in the project file) to the template with -a; another problem I was facing.




回答2:


Answering as another method to accomplish this.

  1. You could change your .tt as TextTemplatingFilePreprocessor (descibed better here: http://www.olegsych.com/2009/09/t4-preprocessed-text-templates/).
  2. Create small command line tool that executes the preprocessor on pre-build event.

The first link includes this example, but it describes the use of preprocessed class: http://blogs.clariusconsulting.net/pga/vs10-beta-1-t4-preprocessing-part-2/



来源:https://stackoverflow.com/questions/8565351/t4-templates-per-template-transformonbuild-setting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!