我在弄清楚如何在 MSBuild 中正确转义双引号时遇到问题 FileUpdate
目标,在 ReplacementText
属性。
我想做的事情很简单。我要搜索AssemblyFileVersion("1.0.0.0")
并将其替换为 AssemblyFileVersion("1.0.0.<revision number here>")
。我正在使用 FileUpdate
元素看起来像这样:
<FileUpdate Files="Properties\AssemblyInfo.cs" Regex="AssemblyFileVersion(\(\x22)(\d+)\.(\d+)\.(\d+)\.(\d+)" ReplacementText="AssemblyFileVersion$1$2.$3.$4.$(build_vcs_number_1)" />
这工作得很好,但是看起来确实是一种奇怪的方法!基本上,因为我无法在 ReplacementText
中使用双引号。属性,我必须将正则表达式字符串中的 "分组,然后使用组号将 "插入 ReplacementText
(实际上,我对 ( 和 "进行了分组,但我只需要对 "进行分组)。
我已经尝试了所有标准方法 -\"、""、\x22、\x22、\",但没有任何效果。我一定错过了一些明显的东西,但它是什么?
尴尬...
最佳答案
在 *ML 中,带引号的字符串使用 "
来表示引号。
例如:
<FileUpdate Files="Properties\AssemblyInfo.cs" Regex="(AssemblyFileVersion\("\d+\.\d+\.\d+\.)\d+("\))" ReplacementText="$1$(build_vcs_number_1)$2" />
您也可以使用单引号,如下所示:
<FileUpdate Files="Properties\AssemblyInfo.cs" Regex='(AssemblyFileVersion\("\d+\.\d+\.\d+\.)\d+("\))' ReplacementText="$1$(build_vcs_number_1)$2" />
关于regex - MSBuild FileUpdate 目标的 ReplacementText 字符串中的双引号出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8129402/