Based on this thread. I’ve tried to replace the set the current version of my project in my NAnt script.
Here’s my Replace snippet
<target name="Replace">
<loadfile file="${SetVersionCpp.File}" property="h.file.content" />
<regex
input="${h.file.content}"
pattern="(?'BEFORE'[.\s]*)${LineBegining}\s*[\s\d,]*\r\n(?'AFTER'[.\s]*)" />
<echo
file="${SetVersionCpp.File}"
message="${BEFORE}${LineBegining} ${ReplaceWith}
${AFTER}"
append="false"
verbose="true" />
</target>
Which I call on this file
#define FILEVER 0, 2, 0, 3
#define PRODUCTVER 0, 2, 0, 3
#define STRFILEVER "00.02.00.03\0"
#define STRPRODUCTVER "00.02.00.03\0"
with the following parameters
<property name="SetVersionCpp.File" value="${baseline.dir}\VersionNo.h" />
<property name="LineBegining" value="#define FILEVER" />
<property name="ReplaceWith" value="${FileVersion}" />
Based on the output, the AFTER variable is not capturing the rest of the file for some reason. This is what I get:
[#define FILEVER 0, 2, 0, 30
]
*I put it in brackets so that the whitespace got correctly formatted
Any ideas what I’m doing wrong?
I’ve fixed it by setting the
optionstoSinglelineso that.would match line breaks and by removing the classes from the groups: