T4 template will not transform with build

后端 未结 4 601
一个人的身影
一个人的身影 2021-01-11 09:14

I\'m using VisualStudio Ultimate 2012 (Update 1) on Windows 7. I can get my T4 template to generate a file by: right click [tt file] | run Custom tool. That works g

相关标签:
4条回答
  • 2021-01-11 09:54

    One of our customers had exactly the same problem and GarethJ is correct, that this can't be done out-of-the-box.

    However, you can write your own "TextTransform.exe" tool which provides the Visual Studio Automation API to the templates pretty easily. All you need to do is implement the ITextTemplatingEngineHost and the IServiceProvider interfaces and returning an instance of the DTE interface when one is requested.

    That said: We wrote a Blog-Post about this scenario and published the Tool = Source Code as well.

    One Note though: You need a properly licensed installation of Visual Studio on your build server for this to work.

    matthid @ AIT

    0 讨论(0)
  • 2021-01-11 09:57

    I'm afraid that you can't successfully run templates at build time that make use of the Host variable to get at IDE services like the DTE, as the msbuild T4 host is designed to work both from the command line as well as builds in the IDE, and as such, does not expose the global service provider or DTE to templates. The same is true from texttransform.exe, the simple command-line host.

    0 讨论(0)
  • 2021-01-11 09:57

    There is a pro-feature in tangible T4 Editor called Transform On Build which allows you to mark a template as "transform on build" in solution explorers property grid. This will transform the template each time you build within Visual Studio (not build server). There your templates also have access to EnvDTE and other visual studio variables. See: http://t4-editor.tangible-engineering.com/blog/transforming-t4-templates-on-build.html

    0 讨论(0)
  • 2021-01-11 09:58

    I had this problem recently in my build process (not using DTE). I resolved it by making sure I only had 1 texttransform.exe on my PC. For some reason, the IDE was using a recent version of texttransform.exe and the msbuild an older one.

    0 讨论(0)
提交回复
热议问题