TeamCity File Content Replacer : string index out of range

919 Views Asked by At

I am trying to use TeamCity File Content Replacer build feature to replace certain keys in my App.config file (.NET console project). As mentioned in official documentation i have specified

Process File : File which i would like to make replacements in
Find what : RegEx which denotes the text i would like to replace
Replace With : TeamCity variable with which i like to replace text

Everything works fine if Replace With text is short enough , for example dummyText works however things go wrong with lengthier values like \\Server675X\Shared\Artifactory\ , the error message received in build logs is as follows :

[File Content Replacer] Applying replacement "\\Server675X\Shared\Artifactory\" to lines matched by pattern "(?<=key="MappingFileLocation" value=").*(?="\/>)" in the files matched by wildcard: **/SolutionName/App.config...

[File Content Replacer] Error replacing "(?<=key="MappingFileLocation" value=").*(?="\/>)" with "\\Server675X\Shared\Artifactory\": string index out of range: 32. Check your settings.

[File Content Replacer] Error replacing file contents: string index out of range: 32

I can see that 32 is exactly the length of replacement string, question is what setting do i need to check/modify to make this replacement possible ?

PS : I am using TeamCity Enterprise 9.1.7 (build 37573)


1

There are 1 best solutions below

0
On BEST ANSWER

Finally found the solution to the problem, the error message is very misleading the actual problem lies in escaping backslash

using \\Server675X\Shared\Artifactory\ gives an error

Error replacing file contents: string index out of range: 32

however when we use \\\\Server675X\\Shared\\Artifactory\\ there is no error, notice how we escaped backslash.

It would have been better to receive a relevant error message saying un-escaped character found or something along these lines.

Hope this helps someone !