用户登录
用户注册

分享至

构建时 T4 转换的产品仅在下一个构建中使用

  • 作者: 我家没隔壁
  • 来源: 51数据库
  • 2023-02-13

问题描述

我有一个 VS 项目,其中包含:

I have a VS project that contains:

  1. 在 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.

软件
前端设计
程序设计
Java相关