regex - MSBuild FileUpdate 目标的 ReplacementText 字符串中的双引号出现问题

标签 regex visual-studio-2010 .net-4.0 msbuild

我在弄清楚如何在 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\(&quot;\d+\.\d+\.\d+\.)\d+(&quot;\))" 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/

相关文章:

c# - 找不到从我的 Windows 服务中删除/重新启动内存中的 DLL 状态的方法

c# - WPF 中的 ContextMenu 太宽

javascript - 我的正则表达式中的非捕获组有什么问题

ruby - 如何使用 Regex 匹配前面没有 "="的单词?

javascript - 从 JavaScript 中的地址中删除邮政编码

c# - 生成操作 : Content - how do get it to the Executing Assemblies folder instead of just the project folder?

c# - 外部jar文件包含在monodroid的java绑定(bind)库中吗?

c# - 在 Visual Studio 中复制现有 ASPX 页面的最佳方法

regex - 从文本文件中提取所有数字并将它们存储在另一个文件中

Silverlight 4/.NET 4 调试资源字符串