Displaying the build date

前端 未结 25 2312
感动是毒
感动是毒 2020-11-22 11:36

I currently have an app displaying the build number in its title window. That\'s well and good except it means nothing to most of the users, who want to know if they have t

25条回答
  •  失恋的感觉
    2020-11-22 12:18

    One approach which I'm amazed no-one has mentioned yet is to use T4 Text Templates for code generation.

    <#@ template debug="false" hostspecific="true" language="C#" #>
    <#@ assembly name="System.Core" #>
    <#@ import namespace="System" #>
    <#@ output extension=".g.cs" #>
    using System;
    namespace Foo.Bar
    {
        public static partial class Constants
        {
            public static DateTime CompilationTimestampUtc { get { return new DateTime(<# Write(DateTime.UtcNow.Ticks.ToString()); #>L, DateTimeKind.Utc); } }
        }
    }
    

    Pros:

    • Locale-independent
    • Allows a lot more than just the time of compilation

    Cons:

    • Only applicable to libraries where you control the source
    • Requires configuring your project (and build server, if that doesn't pick it up) to execute the template in a pre-build step. (See also T4 without VS).

提交回复
热议问题