Compile date and time

后端 未结 3 527
情歌与酒
情歌与酒 2020-12-14 19:21

Is there some clever way of getting the date and time of when the dll was built/compiled?

I’m using the assembly version numbering and reflection to retrieve and dis

相关标签:
3条回答
  • 2020-12-14 19:48

    What about:

    new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;
    
    0 讨论(0)
  • 2020-12-14 19:56

    You can get it by this way:

    File.GetLastWriteTime(Assembly.GetExecutingAssembly().Location);
    

    Returns DateTime object.

    0 讨论(0)
  • 2020-12-14 20:00

    If you set the assembly version (usually in AssemblyInfo.cs) to Major.Minor.* (e.g. 1.0.*), then you can probably retrieve the build date at runtime with something like this:

    var version = Assembly.GetExecutingAssembly().GetName().Version;
    DateTime buildDate = new DateTime(2000, 1, 1)
        .AddDays(version.Build)
        .AddSeconds(version.Revision*2);
    

    When using a * for the third and fourth part of the assembly version, then these two parts are set automatically at compile time to the following values:

    • third part is the number of days since 2000-01-01
    • fourth part is the number of seconds since midnight divided by two (although some MSDN pages say it is a random number)

    Oh, and you have to take care of daylight saving time yourself (e.g. add one hour if it's daylight saving time).

    0 讨论(0)
提交回复
热议问题