使用VS 2012编译生成T4 [英] Generating T4 on Build using VS 2012
问题描述
我想生成使用VS2012我的项目的每一个版本的代码
I am trying to generate code on every build of my project using VS2012.
我在我的解决方案3个项目:
I have 3 projects in my solution :
- 项目1有一些班
- 项目2拥有通用模板
- 项目3个有模板读取JSON文件,然后调用通用模板形式的项目2生成的文件。
当我点击编译/变换所有T4模板,是没有问题的,发电顺利。
When I am clicking on Build/Transform All T4 Templates, there is no problem, the generation goes well.
不过,我想我的生成配置,包括自动在每一个建设这一步。
But I am trying to configure my build to include this step automatically on every build.
我加入这个代码,以我的csproj:
I have added this code to my csproj :
<Import Project="$MsBuildToolsPath)\Microsoft.CSharp.Targets" />
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
<OverWriteReadOnlyOutputFiles>true</OverWriteReadOnlyOutputFiles>
</PropertyGroup>
<Import Project="$(MSBuildExtensionPath32)\Microsoft\VisualStudio\v11.0\TextTemplating\Microsoft.TextTemplating.targets"/>
我已经作出了自己的道路的 \Microsoft\VisualStudio\v11。 0\TextTemplating\Microsoft.TextTemplating.targets 的从我在我的电脑中。
我把它从这个例子是:的获得视觉工作室可以运行-A-T4模板上,每建造
I have made up myself the path "\Microsoft\VisualStudio\v11.0\TextTemplating\Microsoft.TextTemplating.targets" from what I found on my pc. The example I took it from was :get-visual-studio-to-run-a-t4-template-on-every-build
问题来源于此行我使用:
<#@ include文件=$(SolutionDir)\xxx\yyy\zzz\mytemplate.tt>
The problem comes from this line I am using : <#@ include file="$(SolutionDir)\xxx\yyy\zzz\mytemplate.tt">
和我收到错误消息:
无法解析包括对文件中的文本:
D:\Projects\pppp\qqq \eeee\ $(SolutionDir)\xxx\yyy\zzz\mytemplate.tt
Failed to resolve include text for file : D:\Projects\pppp\qqq\eeee\$(SolutionDir)\xxx\yyy\zzz\mytemplate.tt
作为模板工程以及当它产生的手动(BUILD /转换所有T4模板),我不知道什么可能是在构建时产生它的问题。
As the template works well when it is generated "by hand" (Build/Transform All T4 Templates), I wonder what might be the problem for generating it at build time.
你知道吗?
推荐答案
现在的问题是,当你在生成过程中运行你的模板就被不同的主机和$(SolutionDir下执行)宏不存在。尝试使用相对路径,而不是如
The problem is that when you are running your template during the build process it is being executed under different host and $(SolutionDir) macro does not exist. Try using relative path instead e.g.
<#@ include file="..\xxx\yyy\zzz\mytemplate.tt">
这篇关于使用VS 2012编译生成T4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!