Automatically update the AssemblyFileVersion attribute of a .NET Assembly
Automatic AssemblyFileVersion Updates
There is support in .NET for automatically incrementing the AssemblyVersion of a project by using the ".*" notation. e.g.
Unfortunately the same functionality isn't available for the AssemblyFileVersion. Often times, I don't want to bump the AssemblyVersion of an assembly as it will effect the strong name signature of the assembly, and perhaps the changes (a bug fix) isn't significant enough to warrant it. However I do want to automatically increment the file version, so that in a deployed environment, I can right click the file and establish when the file was built & released.
[important]Enter the Update-AssemblyFileVersion.ps1 file.[/important]
This powershell script, (heavily borrowed from David J Wise's article), runs as a pre-build command on a .NET Project. Simply point the command at an assembly info file, (or GlobalAssemblyInfo.cs if you're following my suggested versioning tactics) and ta-da, automatically updating AssemblyFileVersions.
The Build component of the version number will be set using the following formula based on a daycount since the year 2000.
# Build = (201X-2000)*366 + (1==>366) # $build = [int32](((get-date).Year-2000)*366)+(Get-Date).DayOfYear
The Revision component of the version number will be using the following formula based on seconds in the current day.
# Revision = (1==>86400)/2 # .net standard # $revision = [int32](((get-date)-(Get-Date).Date).TotalSeconds / 2)
The Major & Minor components are not set to update although they could be. Simply add the following command to your Pre-Build event and you're all set.
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Path\To\Update-AssemblyFileVersion.ps1" -assemblyInfoFilePath "$(SolutionDir)\Project\Properties\AssemblyInfo.cs"