Is there an easy way to configure in a build process to write in the time stamp of the build to be displayed in the application to have something like "This page was last updated: 06/26/2010"
+2
A:
One solution would be to embed this information in an assembly attribute during your build. You can do this using the MSBuild community tasks Time and AssemblyInfo tasks:
<Time>
<Output TaskParameter="Month" PropertyName="Month" />
<Output TaskParameter="Day" PropertyName="Day" />
<Output TaskParameter="Year" PropertyName="Year" />
<Output TaskParameter="Hour" PropertyName="Hour" />
<Output TaskParameter="Minute" PropertyName="Minute" />
<Output TaskParameter="Second" PropertyName="Second" />
</Time>
and
<AssemblyInfo CodeLanguage="CS"
OutputFile="$(MSBuildProjectDirectory)\GlobalInfo.cs"
AssemblyDescription="This page was last updated: $(Month)/$(Day)/$(Year)"
/>
You would then include the source file in your project (GlobalInfo.cs in this example). To access this value in code you would use something like this:
public static string GetAssemblyDescription(Type t)
{
string result = String.Empty;
var items = t.Assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (items != null && items.Length > 0)
{
AssemblyDescriptionAttribute attrib = (AssemblyDescriptionAttribute)items[0];
result = attrib.Description;
}
return result;
}
Type t = typeof(MyClass);
string description = GetAssemblyDescription(t);
Console.WriteLine(description);
Todd
2010-06-16 15:35:42