Im currently facing a problem where I need to have a string with the current version of my application and this needs to change automatically every time Unity is built. After some research Ive come across the following tag:
[assembly:AssemblyVersion ("1.0.*.*")]
But this only seems to work at the AssemblyInfo.cs file, which my .csproj isnt making, so my next step was to manually change this .csproj to include the creation of the .cs, following this Customizing csproj files to autogenerate AssemblyInfo.cs - CodeProject. This didnt work since everytime I run Unity this file will just get rewritten.
There is no completely automatic solution for this.
The easier way would be to implement your own build method using BuildPipeline.BuildPlayer and before calling it just write your version number to the location you want it (Using the Process class you could also call git for the current version).
This has the disadvantage that somebody could still try to build using the normal unity interface and not get the correct build number.
You might also be able to use PostProcessBuild to get the version number after a build and then inject it into it (either as an external file or by rewriting assemblies if you really have to).
To use the methods you found for csproj files you could roll your own csproj/sln instead of auto generating them and only add the final built assemblies to your project.
I actually came across a really simple solution, which is to create a file with only the version number on it and a class with [InitializeOnLoad] tag, which its constructor is static and will parse the version file, increment it and write it.
assembly:AssemblyVersion solution throws an error because of the deterministic flag (google it if you want). I share my simple one script solution since this post is number 1 result on google and I wasted too much time implementing this.