I would suggest using T4 template.
Insert the following code into your project file.
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\TextTemplating\Microsoft.TextTemplating.targets" />
And create .tt file like the following:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ output extension=".cs" #>
namespace MyNamespace
{
public static class Constants
{
public static string LastBuildDate = "<#=DateTime.Now#>";
}
}
It will create the .cs file with content like, for example
namespace MyNamespace
{
public static class Constants
{
public static string LastBuildDate = "07/02/2014 10:34:46";
}
}
Note: the path to the text template targets file may differ depending on installed visual studio version.
Also, you should insert "<Import Project ..." line after the line that imports "Microsoft.CSharp.targets"; otherwise it will not work.