Using raw parameter value in file content replacer without escaping value

Hi there,

I've been using teamcity for a while now, but have only recently starting using its file content replacer build feature. Due to this, we have places where we use a parameter via an MSBuild command $(LogsTargetDirectory) and other places where we've just started using the file content replacer.

I'm finding it works really well, but I'm occasionally having issues when my parameter value contains a special character ($ or \). This is because the replace with field requires those character to be escaped with a backslash even when added via a parameter. I'm aware there is a REGEX_MIXED mode available to me, but I don't believe this gets me what I want either.

What I'm trying to achieve is a replacement value for this line in a web.config:

xml...
<aspNetCore processPath="bin\IISSupport\VSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" stdoutLogEnabled="true" stdoutLogFile="<PARAMETER VALUE HERE>">
...xml

At the moment, my settings are:

LogsTargetDirectory param val: C:\application\Logs\
Find what: ([\s\S]*<configuration[\s\S]*<location[\s\S]*<system.webServer[\s\S]*<aspNetCore.*stdoutLogFile=")\S*("[\s\S]*)
Replace with: $1%system.LogsTargetDirectory%stdout$2

However, what I end up with is (no slashes):
<aspNetCore processPath="bin\IISSupport\VSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" stdoutLogEnabled="true" stdoutLogFile="C:applicationLogsstdout">

After my attempts from this stackoverflow post:

  • I don't believe REGEX_MIXED mode will allow the $1 and $2 capturing groups?
  • Since I'm also using this parameter value for an MSBuild config I don't think I can pre-escape the value either.

What I'd like is to be able to use a syntax similar to %system.LogsTargetDirectory|raw% to ensure my actual value is used, but I don't think this is possible. Can anyone help me out?

0
1 comment

Hi,

 

You are right in that REGEX_MIXED will not allow for the $1 and $2 capturing groups in that regard, although on the other hand, I'm not exactly sure why you need to put the full xml line into the "find" section. You could simply search for a "stdoutLogFile="<placeholder>" and set as replacement "stdoutLogFile="%systemLogsTargetDirectory%stdout"".TeamCity doesn't need to match the full line for the replacer to work, it will just replace the exact part that has been matched. If you could cut it down to a point where the rest of the incoming string is predictable, even if the placeholder varies, you could use REGEX_MIXED to replace for the full "predictable" string and then replace the placeholder.

 

Would that work for you?

0

Please sign in to leave a comment.