nant:replace-all-in-file
Replace a string in a file with nant
File content:
- version.cpp
#include "stdio.h" #define VERSION "x.x.x.x" void main() { }
Create replace.build file to replace version with $BuildNumber:
- 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*"[x][\.][x][\.][x][\.][x]"(?'AFTER'[\w\s\W]*)" /> <echo file="${version.file}" message="${BEFORE}#define VERSION "${BuildNumber}"${AFTER}" append="false" /> </target> </project>
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