开发者

Determine whether DateTime was baked into Version of .NET assembly at compile time?

开发者 https://www.devze.com 2023-04-13 05:44 出处:网络
How do I know that adding the Build and Revision values of a given .NE开发者_开发知识库T assembly to new DateTime(2000, 1, 1) will give me the compile time?

How do I know that adding the Build and Revision values of a given .NE开发者_开发知识库T assembly to new DateTime(2000, 1, 1) will give me the compile time?

Put another way: how do I know that the [assembly: AssemblyVersion("1.0.*")] attribute was used for the assembly at compile time?


You don't. The AssemblyVersionAttribute just stores a bunch of numbers. Those numbers could be:

  • Manually assigned
  • Auto-incremented
  • Based on date and time
  • Based on source control revision numbers

There's nothing in AssemblyVersionAttribute to tell you this.


You could use this:

static string TimestampFromVersion(string version)
{
    string[] versionComponents = version.Split('.');
    DateTime potentialCompilationDate = (new DateTime(2000, 1, 1)).AddDays(versionComponents[2]).AddSeconds(2 * versionComponents[3]);
    return potentialCompilationDate.ToString("dd MMM yyyy, HH:mm:ss");
}

and check against the file's timestamp...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号