【问题标题】:Using NAnt filterchain to instantiate multiple template files使用 NAnt filterchain 实例化多个模板文件
【发布时间】:2011-11-07 17:46:28
【问题描述】:

我有一组模板文件,比如

<!-- @TEMPLATE@ -->
<!-- @DONOTEDIT@ -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SuperDuper @VARIANT@</title>
</head>
<body>
...
  @PRODUCTCODENAME@
...
</body>

我想使用NAnt 进行部署,以便实例化嵌入的关键字,如

<target name="deployTemplates">
  <property name="_buildstamp" value="${DestDir}/templates_buildstamp"/>
  <uptodate property="_uptodate" verbose="${Verbose}">
    <sourcefiles basedir="${TemplateDir}">
      <include name="**"/>
    </sourcefiles>
    <targetfiles>
      <include name="${_buildstamp}"/>
    </targetfiles>
  </uptodate>
  <if test="${not _uptodate}">
    <copy todir="${CourseDestDir}" verbose="${Verbose}" overwrite="True">
      <!-- Have to specify the fileset again to maintain directory structure. -->
      <fileset basedir="${TemplateDir}">
        <include name="**"/>
      </fileset>
      <filterchain>
        <replacetokens>
          <token key="DONOTEDIT" value="Do not edit, will be overwritten."/>
          <token key="PRODUCTCODENAME" value="${Product}"/>
          <token key="VARIANT" value="${Variant}"/>
        </replacetokens>
      </filterchain>
    </copy>
    <touch file="${_buildstamp}"/>
  </if>
</target>

但是如何将各个模板文件的名称嵌入到每个部署的文件中,也就是说,将@TEMPLATE@ 替换为模板文件的位置,以便其他人知道在哪里进行永久更改?

【问题讨论】:

    标签: nant


    【解决方案1】:

    查看 NAnt source code&lt;filterchain&gt; 文档 - 您将必须实现自定义 Filter,这使得当前文件名可用于替换。 existing filters 不会公开此信息。

    【讨论】:

      猜你喜欢
      • 2014-02-17
      • 1970-01-01
      • 2011-04-06
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多