Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
蚂蚁替换任务的Nant等价物_Ant_Nant - Fatal编程技术网

蚂蚁替换任务的Nant等价物

蚂蚁替换任务的Nant等价物,ant,nant,Ant,Nant,在Nant中寻找蚂蚁替换任务的等价物在Nant中没有直接等价物 此链接有两个选项 据我所知,这正是你想要的。受和任务的支持,您可以定义令牌替换表达式,该表达式将在文件复制/移动操作期间转换文件内容。您可以编写自定义任务: <target name="deftask-replregexp" description="define custum task like ants task replaceregexp"> <script language="C#"&g

在Nant中寻找蚂蚁替换任务的等价物

在Nant中没有直接等价物


此链接有两个选项

据我所知,这正是你想要的。受
任务的支持,您可以定义令牌替换表达式,该表达式将在文件复制/移动操作期间转换文件内容。

您可以编写自定义任务:

<target name="deftask-replregexp"
        description="define custum task like ants task replaceregexp">
  <script language="C#">
    <!-- NAnt 0.92 reference states that this is loaded by default. Do not 
         know why this is required. --> 
    <references>
      <include name="System.dll"/>
    </references>
    <imports> 
      <import namespace="System.Text.RegularExpressions" />
    </imports>
    <code>               
      <![CDATA[
        [TaskName("replaceregexp")]
        public class ReplaceRegExp : Task 
        {

          #region Public Instance Properties

          [TaskAttribute("file", Required=true)]
          public string InFile { get; set; }

          [TaskAttribute("match", Required=true)]
          public string Match { get; set; }

          [TaskAttribute("replace", Required=true)]
          public string Replace { get; set; }

          #endregion Public Instance Properties

          #region Override implementation of Task

          protected override void ExecuteTask() 
          {
            if ( !File.Exists(this.InFile) )
            {
              throw new BuildException("The file \"" + this.InFile 
                                       + "\" does " + "not exist.");              
            }
            doReplaceRegExp( this.InFile, this.Match, this.Replace);
          }
          private static void doReplaceRegExp(String inFile, 
                                              String pattern, 
                                              String replacement)
          {
            String outFile = Path.GetTempFileName();
            Regex regex = new Regex(pattern, RegexOptions.Compiled
                                             | RegexOptions.IgnoreCase);
            bool replaceDone = false;
            try
            {
              using (StreamReader input = new StreamReader(inFile, true))
              using (TextWriter output = new StreamWriter(
                                              new FileStream(outFile,
                                                             FileMode.Create),
                                              input.CurrentEncoding))
              {
                  String line;
                  do
                  {
                      line = input.ReadLine();
                      if (line != null)
                      {
                          System.Text.RegularExpressions.Match m 
                              = regex.Match(line);
                          if (m.Success)
                          {
                              replaceDone = true;
                              line = regex.Replace(line, replacement, 1);
                          }
                          output.WriteLine(line);
                      }
                  } while (line != null);
                  input.Close();
                  output.Close();
              }
              if (replaceDone)
              {
                  File.Copy(outFile, inFile, true);
              }
            }
            finally
            {
              if (outFile != null && File.Exists(outFile))
              {
                  File.Delete(outFile);
              }
            }
          }

          #endregion Override implementation of Task
        }
      ]]>
      </code>
    </script>
</target>



等效方法是在复制或移动任务中使用filterchain和filters。