Questions about the App version number inside Project.xml



  • Hi,

    I use a version number to check a lot of things in my game between releases. But sometimes I forget to set that number before launching my game... So I have two questions:

    1- Can the App version inside the Project.xml be set at compiling time?
    (For version number, I use YYMMDD, so today's version is 160812)

    2- Can I retrieve the App version number from the Project.xml inside my code?

    Thanks :)



  • Can't say about Project.xml, but I use these macro:

    package build;
    
    #if macro
    import sys.io.Process;
    #end
    
    class BuildInfo 
    {
    	macro public static function buildDate()
    	{
    		var ret = Date.now().toString();
    		return macro $v{ret};
    	}
    
    	macro public static function gitVersion()
    	{
    		var branch = new sys.io.Process("git", ["rev-parse", "--abbrev-ref", "HEAD"]).stdout.readLine();
    		var version = new sys.io.Process("git", ["describe", "--always"]).stdout.readLine();
    		var ret = version + "-" + branch;
    		return macro $v{ret};
    	}
    }
    

    Then call functions defined here, and they are replaced with strings at compile time



  • For question 2 you can just use Lib.version

    I would love to know if there's a way to tick up the version number when compiling tho



  • Thanks for the responses.
    @zkylon, is that the Lib from flash.Lib ?

    I released a version yesterday and once again I totally forgot to set the version number... So I think I'll stick to @starry-abyss' code.

    I'll try to change the Project.xml version number using a bat file that will replace the version text with the current date and launch the compilation. It should be possible...



  • Note that the code I posted works as is without any .bat files
    For gitVersion to work you may need to include path to git.exe in PATH environment variable



  • @Txori that'd be openfl.Lib, but if the automated system works better for you go ahead

    @starry-abyss do you know of a similar solution for Mercurial? That'd be pretty useful

    Thanks



  • @zkylon No, but all the function does is invokes
    git rev-parse --abbrev-ref HEAD
    and
    git describe --always
    and inserts the output into the code.
    So you can substitute git with any console tool that supports arguments (arguments will be different of course for every tool) and standard output.



  • @starry-abyss Thanks, that's really helpful, I had no real experience using Process or macros (I ended up not using macros because I don't quite understand them at this point) but got the desired result by doing:

     var version = new sys.io.Process("hg", ["identify", "-n"]).stdout.readLine();
    

    In case another Mercurial user finds this thread


Log in to reply