T4 template will not transform with build

前提是你 提交于 2019-12-01 02:40:58

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.

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

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

Wolfgang Grinfeld

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.

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