使用Ant构建更新数量和注入源$ C ​​$ C [英] Use ANT to update build number and inject into source code

查看:102
本文介绍了使用Ant构建更新数量和注入源$ C ​​$ C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的build.xml文件,我在递增,像这样一个属性文件构建版本编号:

In my build.xml file I am incrementing a build version number in a property file like so:

<target name="minor">
     <propertyfile file="build_info.properties">
         <entry key="build.minor.number" type="int" operation="+" value="1" pattern="00" />
         <entry key="build.revision.number" type="int" value="0" pattern="00" />
     </propertyfile>
</target>

我也有一个主要的和修订相似的条目。 (从<一个href=\"http://stackoverflow.com/questions/1431315/build-numbers-major-minor-revision\">http://stackoverflow.com/questions/1431315/build-numbers-major-minor-revision)

这个伟大的工程。现在,我想借此增加版本号,并将其注入到我的源$ C ​​$ C:

This works great. Now I would like to take this incremented build number and inject it into my source code:

    //Main.as
    public static const VERSION:String = "@(#)00.00.00)@";

使用:

<target name="documentVersion">
    <replaceregexp file="${referer}" match="@\(#\).*@" replace="@(#)${build.major.number}.${build.minor.number}.${build.revision.number})@" />
</target>

现在这个八九不离十的作品。它确实替换版本的的使用过时的版本号。所以每当我运行Ant脚本build_info.properties更新到正确的版本,但我的源$ C ​​$ C文件使用pre更新值。

Now this sorta works. It does indeed replace the version but with the outdated version number. So whenever I run the ANT script the build_info.properties is updated to the correct version but my source code file is using the pre updated value.

我也赞同检查,确实我递增的内部版本号之前我所说的更换,我已经注意到,呼应:

I have echoed to check that indeed I am incrementing the build number before I call the replace and I have noticed that echoing:

<echo>${build.minor.number}</echo> 
//After updating it still shows old non updated value here but the new value in the property file.

那么,有没有一种方法来检索属性文件更新后的值,所以我可以用它来注入到我的源$ C ​​$ C?

So is there a way to retrieve the updated value in the property file so I can use it to inject into my source code?

干杯

推荐答案

所以花费数小时不能够解决这个问题后,我张贴了这个问题,然后弄明白20分钟后。

So after spending hours not being able to solve this, I post this question and then figure it out 20 minutes later.

问题是我有这个在我的构建文件的顶部:

The problem was I had this at the top of my build file:

<property file="build_info.properties"/>

我想这是因为划定范围和性质是不可变的所以我从来没有能够更新值。删除这一行,然后添加以下得到它的完美的工作:

I guess it was due to scoping and that properties are immutable thus I was never able to update the value. Removing that line and then adding the following got it working perfectly:

<target name="injectVersion">
     <property file="build_info.properties"/>
     <replaceregexp file="${referer}" match="@\(#\).*@" replace="@(#)${build.major.number}.${build.minor.number}.${build.revision.number})@" />
</target>

这篇关于使用Ant构建更新数量和注入源$ C ​​$ C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆