I was just wondering how I could automatically increment the build (and version?) of my files using Visual Studio (2005).
If I look up the properties of say C:\Windows\notepad.exe
, the Version tab gives "File version: 5.1.2600.2180". I would like to get these cool numbers in the version of my dll's too, not version 1.0.0.0, which let's face it is a bit dull.
I tried a few things, but it doesn't seem to be out-of-box functionality, or maybe I'm just looking in the wrong place (as usual).
I work with mainly web projects....
I looked at both:
- http://www.codeproject.com/KB/dotnet/Auto_Increment_Version.aspx
- http://www.codeproject.com/KB/dotnet/build_versioning.aspx
and I couldn't believe it so much effort to do something is standard practice.
EDIT: It does not work in VS2005 as far I can tell (http://www.codeproject.com/KB/dotnet/AutoIncrementVersion.aspx)
As of right now, for my application,
returns
ver = 1.0.3251.27860
The value 3251 is the number of days since 1/1/2000. I use it to put a version creation date on the splash screen of my application. When dealing with a user, I can ask the creation date which is easier to communicate than some long number.
(I'm a one-man dept supporting a small company. This approach may not work for you.)
Changing the AssemblyInfo works in VS2012. It seems strange that there's not more support for this in Visual Studio, you'd think this was a basic part of the build/release process.
AssemblyInfoUtil. Free. Open-source.
To get incrementing (DateTime) information into the AssemblyFileVersion property which has the advantage of not breaking any dependencies.
Building on Boog's solution (did not work for me, maybe because of VS2008?), you can use a combination of a pre-build event generating a file, adding that file (including its version properties) and then using a way to read out those values again. That is..
Pre-Build-Event:
Include the resulting VersionInfo.cs file (Properties subfolder) into your project
Code to get Date back (years down to seconds):
Not very comfortable.. also, I do not know if it creates a lot of force-rebuilds (since a file always changes).
You could make it smarter for example if you only update the VersionInfo.cs file every few minutes/hours (by using a temporary file and then copying/overwriting the real VersionInfo.cs if a change large enough is detected). I did this once pretty successfully.
Maybe, for this task, you can use code like this:
and call it from form loading.
With this code you can update any part of file info in AssemblyInfo.cs (but you must use "standard" directory structure).