To extend RobinDotNet solution:
Protip: you can automatically run a program or script to do this for you from within the .csproj configuration file of MSBuild every time you build. I did this for one web application that I currently support by running the Cygwin bash shell script to do some h4x version control, to calculate the version number from the Git history, and then pre-process the assembled assembly source information file in the assembly output.
A similar thing can be done to analyze the ClickOnce version number from the project file, i.e. Project.PropertyGroup.ApplicationRevision and Project.PropertyGroup.ApplicationVersion (although I donβt know what the version line means, but you can just guess until it breaks and fix it) and insert this version information into the assembly information.
I donβt know when the ClickOnce version is clicked, but probably after the build process, so you may need to tinker with this solution to compile the new number. I assume there is always /*h4x*/ +1 .
I used Cygwin because * nix scripting is much better than Windows, and the interpreted code eliminates the need to create your pre-build before creating it, but you could write the program using whatever technique you wanted (including C # / .NET). The pre-processor command line is inside PreBuildEvent :
<PropertyGroup> <PreBuildEvent> $(CYGWIN_ROOT)bin\bash.exe --login -c refresh-version </PreBuildEvent> </PropertyGroup>
Do you think this happens before the build phase, so you can effectively pre-process the source code before compiling it. I did not want to automatically edit the Properties\AssemblyInfo.cs file, so for its safe use I created a Properties\VersionInfo.base.cs file that contained a text template of the class with version information and was marked as BuildAction=None in the project so that it would not be compiled with project:
using System.Reflection; using EngiCan.Common.Properties; [assembly: AssemblyVersion("0.$REVNUM_DIV(100)$.$REVNUM_MOD(100)$.$DIRTY$")] [assembly: AssemblyRevisionIdentifier("$REVID$")]
(A very simple and dirty placeholder syntax similar to Windows environment variables with the added extra h4x was used for simplicity / complexity)
AssemblyRevisionIdentifierAttribute was a custom attribute that I created to store Git SHA1, since it is much more meaningful to developers than abcd
My refresh-version program will then copy this file to Properties\VersionInfo.cs , and then replace the version information that it has already calculated / analyzed (I used sed(1) to substitute, which was another advantage of using Cygwin). Properties\VersionInfo.cs been compiled into a program. This file may start empty, and you should ignore it in your version control system, because it automatically changes, and the information for its creation is already stored in another place.