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 sa
It was not enough for me adding
[assembly: AssemblyVersion("1.0.*")]
When building it throws me this error
The specified version string does not conform to the required format
The format was finally accepted after I set Deterministic
to False
in project.csproj
<Deterministic>false</Deterministic>
For some reason setting Deterministic
to False
messed up my config file loading it and saving it on different locations.
I setup a post-build event to increment the revision number:
This calls a powershell script named autoincrement_version.ps1
passing as argument the path of AssemblyInfo.cs
if $(ConfigurationName) == Release (
PowerShell -ExecutionPolicy RemoteSigned $(ProjectDir)autoincrement_version.ps1 '$(ProjectDir)My Project\AssemblyInfo.cs'
)
It autoincrements the revision number using Regex
param( [string]$file );
$regex_revision = '(?<=Version\("(?:\d+\.)+)(\d+)(?="\))'
$found = (Get-Content $file) | Select-String -Pattern $regex_revision
$revision = $found.matches[0].value
$new_revision = [int]$revision + 1
(Get-Content $file) -replace $regex_revision, $new_revision | Set-Content $file -Encoding UTF8
Each time I do a build it auto-increments the least-significant digit.
I don't have any idea how to update the others, but you should at least be seeing that already...
In visual Studio 2008, the following works.
Find the AssemblyInfo.cs file and find these 2 lines:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
You could try changing this to:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
But this won't give you the desired result, you will end up with a Product Version of 1.0.* and a File Version of 1.0.0.0. Not what you want!
However, if you remove the second of these lines and just have:
[assembly: AssemblyVersion("1.0.*")]
Then the compiler will set the File Version to be equal to the Product Version and you will get your desired result of an automatically increment product and file version which are in sync. E.g. 1.0.3266.92689
Set the version number to "1.0.*" and it will automatically fill in the last two number with the date (in days from some point) and the time (half the seconds from midnight)
Go to Project | Properties and then Assembly Information and then Assembly Version and put an * in the last or the second-to-last box (you can't auto-increment the Major or Minor components).
To get the version numbers try
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Reflection.AssemblyName assemblyName = assembly.GetName();
Version version = assemblyName.Version;
To set the version number, create/edit AssemblyInfo.cs
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
Also as a side note, the third number is the number of days since 2/1/2000 and the fourth number is half of the amount of total seconds in the day. So if you compile at midnight it should be zero.