我有一个问题,想知道如何在我的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,\”,没有任何效果。 我必须在这里遗漏一些明显的东西,但它是什么?
尴尬...
I have an issue figuring out how to escape double quotes properly in my MSBuild FileUpdate target, in the ReplacementText attribute.
What I'm trying to do is very simple. I want to search for AssemblyFileVersion("1.0.0.0") and replace it with AssemblyFileVersion("1.0.0.<revision number here>"). I'm using a FileUpdate element that looks like this:
<FileUpdate Files="Properties\AssemblyInfo.cs" Regex="AssemblyFileVersion(\(\x22)(\d+)\.(\d+)\.(\d+)\.(\d+)" ReplacementText="AssemblyFileVersion$1$2.$3.$4.$(build_vcs_number_1)" />This works fine, but it sure seems like a strange way to do it! Basically, since I wasn't able to get double quotes to work in the ReplacementText attribute, I had to group the " from the Regex string, and then use the group number to insert the " into the ReplacementText (actually, I grouped the ( and the ", but I only needed to group the ").
I've tried all of the standard methods -- \", "", \x22, \x22, \", and nothing works. I must be missing something obvious here, but what is it?
Embarrassed...
最满意答案
在* 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" />In *ML in quoted strings use " to represent quotes.
For example:
<FileUpdate Files="Properties\AssemblyInfo.cs" Regex="(AssemblyFileVersion\("\d+\.\d+\.\d+\.)\d+("\))" ReplacementText="$1$(build_vcs_number_1)$2" />You could probably also use single quotes instead, like so:
<FileUpdate Files="Properties\AssemblyInfo.cs" Regex='(AssemblyFileVersion\("\d+\.\d+\.\d+\.)\d+("\))' ReplacementText="$1$(build_vcs_number_1)$2" />更多推荐
ReplacementText,FileUpdate,AssemblyFileVersion,电脑培训,计算机培训,IT培训"/> &l
发布评论