使用 ANT 更新内部版本号并注入源代码 [英] Use ANT to update build number and inject into source code

查看:22
本文介绍了使用 ANT 更新内部版本号并注入源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 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>

对于主要和修订版,我也有类似的条目.(来自内部版本号:major.minor.revision)

I also have similar entries for the major and revision. (from Build numbers: major.minor.revision)

这很好用.现在我想将这个递增的内部版本号注入到我的源代码中:

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>

现在这种方式有效.它确实用过时的版本号替换了 but 版本.因此,每当我运行 ANT 脚本时,build_info.properties 都会更新为正确的版本,但我的源代码文件使用的是预先更新的值.

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.

那么有没有办法在属性文件中检索更新的值,以便我可以用它来注入我的源代码?

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 更新内部版本号并注入源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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