samedi 26 juillet 2014

Déterminer si DateTime a été cuite dans l'assembly de la Version de .NET au moment de la compilation ? -Débordement de pile


How do I know that adding the Build and Revision values of a given .NET 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...



How do I know that adding the Build and Revision values of a given .NET 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 commentaires:

Enregistrer un commentaire