User Tools

Site Tools


nant:replace-all-in-file
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


Next revision
nant:replace-all-in-file [2019/08/23 10:40] – created odefta
Line 1: Line 1:
 +====== Replace a string in a file with nant ======
 +
 +File content:
 +<file cpp version.cpp>
 +  #include "stdio.n"
 +  #define VERSION "x.x.x.x"
 +  void main() {
 +  }
 +</file>
 +
 +Create replace.build file to replace version with $BuildNumber:
 + <file xml replace.build>
 +<version="1.0" encoding="utf-8" ?>
 +<project name="replace.line" default="replace">
 +  <target name="replace" descripton="replaces a line">
 +    
 +<loadfile file="${version.file}" property="version.file.content" />
 +  <regex
 +      input="${version.file.content}"
 +      pattern="(?'BEFORE'[\w\s\W]*)#define\sVERSION\s*&quot;[x][\.][x][\.][x][\.][x]&quot;(?'AFTER'[\w\s\W]*)" />
 +   <echo
 +      file="${version.file}"
 +      message="${BEFORE}#define VERSION &quot;${BuildNumber}&quot;${AFTER}"
 +      append="false" />
 +
 +</target>
 +
 +</project>
 + </file>
 +
 +
 +Run it with: 
 +  nant -buildfile:replace.build -D:version.file=version.cpp -D:BuildNumber=9.1.0.1
 +
  
nant/replace-all-in-file.txt · Last modified: 2023/07/04 19:36 by 127.0.0.1