MSBuild FileUpdate目标的ReplacementText字符串中出现双引号问题(Having trouble with double quotes in ReplacementText

编程入门 行业动态 更新时间:2024-10-19 20:36:31
MSBuild FileUpdate目标的ReplacementText字符串中出现双引号问题(Having trouble with double quotes in ReplacementText string for MSBuild FileUpdate target)

我有一个问题,想知道如何在我的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中引用的字符串使用&quot; 代表报价。

例如:

<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" />

In *ML in quoted strings use &quot; to represent quotes.

For example:

<FileUpdate Files="Properties\AssemblyInfo.cs" Regex="(AssemblyFileVersion\(&quot;\d+\.\d+\.\d+\.)\d+(&quot;\))" 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

本文发布于:2023-08-05 20:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   目标   双引号   ReplacementText   FileUpdate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!