Dave
Dave

Reputation: 15016

Having trouble with double quotes in ReplacementText string for MSBuild FileUpdate target

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...

Upvotes: 3

Views: 1752

Answers (1)

Qtax
Qtax

Reputation: 33908

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

Upvotes: 6

Related Questions