How to increment a Version string everytime Unity is built?

Hello!

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 article. This didnt work since everytime I run Unity this file will just get rewritten.

As a side note, Im using Mono for coding and GIT for version control, so the perfect world here would be to use GIT Revision as part of the version string I need, which should be something similar to what I found here, which uses Hudson and SVN.

So, how can I make this work? What am I missing?

Thank you!

Hey There,

It’s not that hard to do this since your script are just a text file to Unity.

  1. Use AssetDatabase to find the script

  2. Read the file into a string.

  3. Use string functions to replace the Version number.

  4. Use File.WriteAll() to write the content back to the file you started off with.

  5. AssetDatabase.Refresh();

Regards,

As of the latest version most applications above no longer work.

Wrote and tested a script that does it for you for Android and iOS (free). Leave a star if it works :slight_smile:

Weaver (Unity Asset Store - The Best Assets for Game Making) has an AppDetails script which gives you automatic build numbering (as an int), as well as a build time stamp (as a DateTime).