使用ANT更新内部版本号并注入源代码
在我的 build.xml 文件中,我在属性文件中增加构建版本号,如下所示:
<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)
这非常有效。现在我想获取这个递增的内部版本号并将其注入到我的源代码中:
//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 就会更新为正确的版本,但我的源代码文件正在使用预先更新的值。
我已经回显以检查在调用替换之前我确实在增加内部版本号,并且我注意到回显:
<echo>${build.minor.number}</echo>
//After updating it still shows old non updated value here but the new value in the property file.
那么有没有一种方法可以检索属性文件中的更新值,以便我可以使用它注入到我的源代码中?
干杯
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>
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)@";
By using:
<target name="documentVersion">
<replaceregexp file="${referer}" match="@\(#\).*@" replace="@(#)${build.major.number}.${build.minor.number}.${build.revision.number})@" />
</target>
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?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因此,在花了几个小时无法解决这个问题后,我发布了这个问题,然后在 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:
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:
为什么不直接使用
?Why not just use
<buildnumber/>
?