Easy part: In Project Properties > Build Events, add a "Pre-build event command line" like this:
"D:\SomePath\MyAssemblyInfoPatcher.exe" "$(ProjectDir)Properties\AssemblyInfo.cs"
Hard part: You provide MyAssemblyInfoPatcher.exe , a program which opens the file specified by its first argument, searches it for this line (ignoring the values there):
[assembly: AssemblyVersion("8888.0.*")]
, replaces the line with one of these (or similar):
[assembly: AssemblyVersion("2016.11.05.2359")]
[assembly: AssemblyVersion("2016.1105.2359.1")]
[assembly: AssemblyVersion("8888.2016.1105.2359")]
, and rewrites the file.
The program derives these values from the system date and time according to a pattern like one of these:
yyyy.mm.dd.hhmm
yyyy.mmdd.hhmm.counter
arbitrary.yyyy.mmdd.hhmm
If you hard-code the pattern you want, your program needs no configuration. For the counter (if you chose it), the program can increment the value it finds in the file. The counter must be word (UInt16) so that incrementing 65535 wraps around to 0. If you want the counter to reset each day, now you need to store a reference date, in a side file or maybe in a comment inside AssemblyInfo.cs. For the arbitrary number, you can re-use what's in the file, or hard-code a replacement.
Time issue: Beginning and ending Daylight Savings Time make the local time occasionally jump ahead by one hour (not a problem) and fall back by one hour (always a worry). To almost-guarantee no duplicate time ranges, you can use UTC or maybe the local time except ignore Daylight Savings Time. Local time without Daylight Savings Time is a compromise used by many web servers, and even the optional automatic date-based version numbering built into VS (it overrides a.b.* with a.b.{days since Jan. 1, 2000 at 00:00}.{seconds since Jan. 1, 2000 at 00:00 divided by 2}, so it is not human readable).
Possible simplifications: •The target filename is always "AssemblyInfo.cs", so it could be specified in the program and omitted from the argument: "$(ProjectDir)Properties". •If VS executes the program with the current directory set to "D:\Users\myusername\Documents\Visual Studio 2010\Projects\solutionfolder\projectfolder\Properties", it doesn't need an argument.
•A program can read its AssemblyVersion via System.Reflection.Assembly.GetExecutingAssembly().GetName().Version .
•File:Properties displays AssemblyFileVersion.
•AssemblyFileVersion (if not specified) defaults to AssemblyVersion .