I am attempting to fix a problem with the SQLite makefile in an MSBuild project using the MSBuildCommunityTasks FileUpdate task.
I need to replace the exact string "$(LTLIBOPTS) $(LTLIBPATHS)" with the exact string "$(LTLIBOPTS) $(LTLIBPATHS) $(TCLLIBPATHS)."
I have figured out a regex that matches the string I am searching for. It is as follows.
\$\x28LTLIBOPTS\x29 \$\x28LTLIBPATHS\x29
The problem is that I cannot figure out what magical incantation to use for the ReplacementText to get it to replace it with the required text. The closest I could get was as follows.
$$\(LTLIBOPTS\) $$\(LTLIBPATHS\) $$\(TCLLIBPATHS\)
I am using the FileUpdate task as follows.
<FileUpdate
Files="$(MSBuildProjectDirectory)\$(SQLITE_DIR)\Makefile.msc"
Regex="\$\x28LTLIBOPTS\x29 \$\x28LTLIBPATHS\x29"
ReplacementText="$$\(LTLIBOPTS\) $$\(LTLIBPATHS\) $$\(TCLLIBPATHS\)" />
This results in the following being inserted in the file.
$\(LTLIBOPTS\) $\(LTLIBPATHS\) $\(TCLLIBPATHS\)
Can someone please tell me what magical incantation I need to use for the ReplacementText?
Thanks.
Also, is there a way to do a file search and replace in MsBuild without having to mess with regular expressions? I hate regular expressions.
I almost had it. The problem was not with the replacement expression. The problem was that MsBuild interprets $(STRING) as variable references. I needed to use %24 instead of $ in the ReplacementText as follows.
<FileUpdate
Condition="!Exists('$(MSBuildProjectDirectory)\$(SQLITE_DIR)\sqlite_patched')"
Files="$(MSBuildProjectDirectory)\$(SQLITE_DIR)\Makefile.msc"
Regex="\$\x28LTLIBOPTS\x29 \$\x28LTLIBPATHS\x29"
ReplacementText="%24(LTLIBOPTS) %24(LTLIBPATHS) %24(TCLLIBPATHS)" />
By the way, I found the .NET Regex Tester at Regex Storm to be a valuable resource. It helped me to figure out that the problem was not with the replacement expression at all.
Once I realized that the problem was not in the replacement expression, the article How to: Escape Special Characters in MSBuild helped me to figure out what to do the solve my problem.
I hope this helps others who might be having the same problem.