问题描述
我有一个 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?
请注意,文本转换输入是动态的,因此无法在设计时完成.
推荐答案
这个问题现在有了百家乐凯发k8的解决方案!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.
这里是来源:https://web.archive.org/web/20140116193428/http://www.olegsych.com/2010/04/understanding-t4-msbuild-integration/
基本上,您只需在项目文件中包含 t4 构建目标并将 transformonbuild 属性设置为 true.
basically, you just include the t4 build targets in your project file and set the transformonbuild property to true.
以下是相关摘录:
true
请注意,microsoft.texttemplating.targets 文件必须包含在 microsoft.csharp.targets 之后.
note that the microsoft.texttemplating.targets file has to be included after the microsoft.csharp.targets.