构建时T4转换的产品仅在下一个构建中使用 [英] Product of build-time T4 transformation is used only in the next build
问题描述
我有一个VS项目,其中包含:
I have a VS project that contains:
-
在
template.tt
上运行TextTransform
生成generated.cs
generated.cs
列为要编译的文件之一(即在项目文件列表中)
generated.cs
listed as one of the files to compile (i.e. in the list of project files)
构建项目时,将执行预构建操作,重新创建generated.cs
,但是VS会编译generated.cs
的先前版本(我猜想它会在构建过程开始时加载到内存中).
When I build the project, the pre-build action is executed, generated.cs
is re-created, but VS compiles the previous version of generated.cs
(which I guess it loaded in memory when the build process started).
如何使构建使用新版本的generated.cs
(即,在预构建操作中生成的版本)?如何强制执行构建命令?
How to make the build use the new version of generated.cs
(i.e. the one generated in the pre-build action)? How to force the build order?
请注意,文本转换输入是动态的,因此无法在设计时完成.
推荐答案
现在有解决此问题的方法! Oleg Sych在他的博客上发表了一篇帖子,详细介绍了如何进行构建时转换.
There's now a solution to this problem! Oleg Sych has a post on his blog detailing how to make transform-at-build-time work.
基本上,您只需将T4构建目标包括在项目文件中,并将TransformOnBuild属性设置为true.
Basically, you just include the T4 build targets in your project file and set the TransformOnBuild property to true.
以下是相关摘录:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" />
请注意,Microsoft.CSharp.targets之后必须包含Microsoft.TextTemplating.targets文件.
Note that the Microsoft.TextTemplating.targets file has to be included AFTER the Microsoft.CSharp.targets.
这篇关于构建时T4转换的产品仅在下一个构建中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!