bdickerson
bdickerson

Reputation: 23

MSBuild How do do String replacement in an item list

Though I have made some good progress on learning MSBuild scripts, I still consider myself a beginner, so please go easy on me.

I have an MSBuild script that runs a Work Item Query and outputs it to a file which I turn around and read with

<ReadLinesFromFile File="output.txt">
<Output ItemName="ItemList"  TaskParameter="Lines"/>
</ReadLinesFromFile>

The lines in the file contain an ID number, a username and a task description. To 'pretty it up', I want to replace usernames in the file with the name of the person, i.e. change jdoe to John Doe, so I think the TextString task in the Extension Pack would be the right thing to do, but I don't get any changes to the list. Once I get this working, I will want to replicate it for all my team members.

<TextString TaskAction="Replace" OldString="@(ItemList)" OldValue="jdoe" NewValue="John Doe">
  <Output PropertyName="ItemList" TaskParameter="NewString"/>
</TextString>
<Message Text="Results: @(ItemList)" />

The script doesn't crash or get an error, but neither does it do the replacement. What is wrong?

Upvotes: 1

Views: 2341

Answers (1)

SoftwareCarpenter
SoftwareCarpenter

Reputation: 3923

You could try the file system task action. I think the problem is you are using a item list instead of a $property element

<MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace" 
TextEncoding="ASCII"  RegexPattern='"Jdoe"' 
Replacement='"John Doe"' 
Files="%(output.txt)"/>

Upvotes: 3

Related Questions