If you work in a team of several developers, and often come across the question, “Who built this latest version and when?”, here’s how you find out.
If an assembly if compiled with debug information, the StackFrame class contains information about its absolute source file names.
public static class BuildInfo { private static string sBuildPath; public static string BuildPath { get { if (!string.IsNullOrEmpty(sBuildPath)) return sBuildPath; StackFrame sf = new StackFrame(true); string s = sf.GetFileName(); if (!string.IsNullOrEmpty(s)) { int i = s.LastIndexOf("\\"); if (i == -1) sBuildPath = s; else sBuildPath = s.Substring(0, i); } else sBuildPath = "."; return sBuildPath; } } }
If the source files are kept in directories named after the developer (e.g. C:\Team\DeveloperName\Project), it is easy to find out who last released a test version of an application.
To find out the build timestamp of an assembly, use these few lines:
public static class BuildInfo { public static DateTime BuildDate { get { System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.FileInfo fileInfo = new System.IO.FileInfo(assembly.Location); return fileInfo.LastWriteTime; } } }