Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to increment a Version string everytime Unity is built?

Discussion in 'Scripting' started by thrmotta, Dec 16, 2014.

  1. thrmotta

    thrmotta

    Joined:
    May 27, 2014
    Posts:
    32
    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:

    Code (CSharp):
    1. [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 http://www.codeproject.com/Articles/27931/Customizing-csproj-files-to-autogenerate-AssemblyI. 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, http://stackoverflow.com/questions/...rp-assembly-version-via-our-ci-platform-hudso, which uses Hudson and SVN.

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

    Thank you!
     
  2. billykater

    billykater

    Joined:
    Mar 12, 2011
    Posts:
    327
    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.
     
    Polymorphik likes this.
  3. thrmotta

    thrmotta

    Joined:
    May 27, 2014
    Posts:
    32
    Last edited: Dec 17, 2014
  4. Mobalus

    Mobalus

    Joined:
    Jul 24, 2019
    Posts:
    1
    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.

    Checkout https://epicnerf.com/unity-auto-increase-build-number/
     
    forestrf likes this.