Instead of the major.minor.build.revision format, I'd like to use date and time for version numbers. Something more like day.month.year.time. Is there a way to change the format of the AssemblyVersion attribute in AssemblyInfo.cs?
5 Answers
You can put whatever numbers you want in there (as long as they don't overflow the data types that contain them in memory) and call them whatever you wish. I am not sure why you would want to do this, however, as the standard format usually has some form of the date stored in the build field.
For example, here is the assembly version format that we use where I work:
5.1.729.1
This tells me that this is an assembly from version 5.1 of the library, built on July 29th, and was the first build of the day. Subsequent builds on the same day simply increment the revision field.

- 344,730
- 71
- 640
- 635
-
1+1 - good answer. If you really want the version to be based on the date, Build is days since 1/1/2000, and Revision is half the seconds since midnight. DateTime.Parse("2000-01-01").AddDays(version.Build).AddSeconds(version.Revision * 2) will give you the build date & time – Scott Ivey Jul 29 '09 at 20:27
-
It's not an easily discernible format, though. It would be nice for that version to automagically increment the way it does now, just using dates and times instead of build numbers. I guess I should have worded the question better: I'd like to change the format of the auto-generated version numbers. – Lee Crabtree Jul 29 '09 at 20:47
-
Woah, should have read the other comment before adding my own. That's exactly what I needed, Scott. – Lee Crabtree Jul 29 '09 at 20:48
-
an alternative is to use 9210 as the build number 9 is the current year and 210 the day of the year. This gives you a little more time before buildnumbers repeat. See also: http://www.paulvanbrenk.com/buildday/ – Paul van Brenk Jul 29 '09 at 20:55
The easiest approach is to write you own build task that handles this and then have the .csproj file call your task to update it with your default rules. There's an article on using a custom MSBuild task to increment version numbers that could serve as a guide. We have done a similar thing here in the past and found it to work well.
I don't believe there are any tools included in VS2005 for doing this, though.

- 27,819
- 25
- 107
- 140
I would suggest sticking to the existing scheme for the version numbers as used by AssemblyVersion
etc - they have well-known meanings and it might confuse people to go against them.
However, you can easily create your own assembly-level attribute and use that for your date/time. Unfortunately the DateTime
type can't be embedded in metadata so you'd probably be best off using a string - but your attribute could convert that to a DateTime
for you at execution time.

- 1,421,763
- 867
- 9,128
- 9,194
You could build the relevant fragment of assemblyinfo code in a build script -- it's easy enough using IronPython or F# as a scripting tool.

- 11,237
- 3
- 31
- 37
If you would like to automatically change these versions with a script or something similar. I would suggest using http://www.codeproject.com/KB/macros/versioningcontrolledbuild.aspx
It can be ran from the command line also.

- 641
- 5
- 7