Product of build-time T4 transformation is used only in the next build(构建时 T4 转换的产品仅在下一个构建中使用)
问题描述
我有一个 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.
这里是来源: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.
以下是相关摘录:
<Import Project="$(MSBuildToolsPath)Microsoft.CSharp.targets" />
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)MicrosoftVisualStudioTextTemplatingv10.0Microsoft.TextTemplating.targets" />
请注意,Microsoft.TextTemplating.targets 文件必须包含在 Microsoft.CSharp.targets 之后.
Note that the Microsoft.TextTemplating.targets file has to be included AFTER the Microsoft.CSharp.targets.
这篇关于构建时 T4 转换的产品仅在下一个构建中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:构建时 T4 转换的产品仅在下一个构建中使用
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
