TeamCity 文件内容替换器:字符串索引超出范围

TeamCity File Content Replacer : string index out of range

我正在尝试使用 TeamCity File Content Replacer 构建功能来替换我的 App.config 文件(.NET 控制台项目)中的某些键。 如 official documentation 中所述,我已指定

处理文件 : 我想在其中进行替换的文件
查找内容 : RegEx 表示我要替换的文本
替换为 : 我想用来替换文本的 TeamCity 变量

如果 Replace With 文本足够短,一切正常,例如 dummyText 有效然而,像 \Server675X\Shared\Artifactory\ 这样的较长值会出错,构建日志中收到的错误消息如下:

[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

我可以看到 32 正好是替换字符串的长度,问题是我需要什么设置 check/modify 才能使这个替换成为可能

PS : 我正在使用 TeamCity Enterprise 9.1.7(内部版本 37573)


终于找到问题的解决方法,报错信息很误导实际问题出在转义反斜杠

使用 \Server675X\Shared\Artifactory\ 给出错误

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

然而当我们使用 \\Server675X\Shared\Artifactory\ 时没有错误,请注意我们是如何转义反斜杠的。

如果收到一条相关的错误消息说 找到未转义的字符 或类似的内容,那就更好了。

希望这对某人有所帮助!