有没有办法在 ANT 中生成 guid? [英] Is there any way to generate a guid in ANT?

查看:38
本文介绍了有没有办法在 ANT 中生成 guid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ant 脚本来管理构建过程.对于 WiX,当我们生成新版本的安装程序时,我需要生成一个新的 guid.任何人都知道如何在ANT中做到这一点?任何使用内置任务的答案都是可取的.但如果我必须添加另一个文件,那也没关系.

I have an ant script to manage out build process. For WiX I need to produce a new guid when we produce a new version of the installer. Anyone have any idea how to do this in ANT? Any answer that uses built-in tasks would be preferable. But if I have to add another file, that's fine.

推荐答案

我会使用 scriptdef task 定义一个简单的 JavaScript 任务来封装 Java UUID 类,就像这样:

I'd use a scriptdef task to define simple javascript task that wraps the Java UUID class, something like this:

<scriptdef name="generateguid" language="javascript">
    <attribute name="property" />
    <![CDATA[
    importClass( java.util.UUID );

    project.setProperty( attributes.get( "property" ), UUID.randomUUID() );
    ]]>
</scriptdef>

<generateguid property="guid1" />
<echo message="${guid1}" />

结果:

[echo] 42dada5a-3c5d-4ace-9315-3df416b31084

如果您有合理的最新 Ant 安装,这应该是开箱即用的.

If you have a reasonably up-to-date Ant install, this should work out of the box.

这篇关于有没有办法在 ANT 中生成 guid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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