【问题标题】:Issues using T4 to generate basic Assembly Information使用 T4 生成基本装配信息的问题
【发布时间】:2018-11-06 20:19:53
【问题描述】:

我在使用 T4 创建最基本的 Assembly Information 时遇到问题 - 谁能帮帮我?

我只是想让下面的代码手动生成一个版本号,这样我就可以看到它可以工作,但编译后的 .cs 文件没有它应该包含的信息。

代码如下:

SharedAssemblyInfo.tt

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
<#
    int major    = 5;
    int minor    = 0;
    int build    = 0;
    int revisions = 0;

    // TODO: Write code here to automatically generate a version

    string version = String.Format("{0}.{1}.{2}.{3}",
                                   major,
                                   minor,
                                   build,
                                   revisions);
#>
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.

using System.Reflection;


[assembly: AssemblyVersion("<#= version #>")]
[assembly: AssemblyFileVersion("<#= version #>")]

这是预期的结果:

SharedAssemblyInfo.cs

using System.Reflection;

[assembly: AssemblyVersion("5.0.0.0")]
[assembly: AssemblyFileVersion("5.0.0.0")]

这里是actual result - 它没有上面的任何汇编代码。

这与我审查过的几个问题类似:this、this 和 this,但即使遵循它们的特定用例,我也无法生成包含我期待的 AssemblyVersion 和 AssemblyFileVersion 属性

【问题讨论】:

  • 我已经查看了该帖子以及@Kenneth K 的其他一些帖子。我应该在问题中加入吗?
  • 执行此操作的方法通常是使用修改已存在的 AssemblyInfo 文件的实用程序。 MSBuild 有这样一个步骤(AssemblyInfoTask)。我的直觉告诉我使用 T4 不会按预期工作。如果你使用 Git,GitVersion 也支持自动更新 AssemblyInfo。
  • Man @Amy,我什至从未听说过 Got 版本,但这似乎很完美!你能把它作为答案让我接受吗?我将修改问题以更抽象地处理“版本控制”

标签: c# .net-assembly t4


【解决方案1】:

从输出中可以看出,您将 .tt 文件配置为 runtime file generator 而不是设计时生成器。

检查文件的自定义工具属性。它应该是 TextTemplateFileGenerator,而不是 TextTemplatingFilePreprocessor:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    • 2012-08-20
    相关资源
    最近更新 更多