MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace": not working

Oct 28, 2010 at 8:32 PM

I don't understand why the replace is not working? Can any one tell me what I am doing wrong.

I used (http://regexlib.com/RETester.aspx) to check the RegexPattern, and I match the line I want to replace.  The file is not read only.

<MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace"            

RegexPattern="^(?=.*?\#define\b)(?=.*?\DATE_STRING\b).*$" 

Replacement="#define DATE_STRING %27$(BuildDate_ddMMMyy)%27" 

        Files="%(SetUpRule.FullPath)"             

       TextEncoding="utf-8"

/>

Log:  Task "MSBuild.ExtensionPack.FileSystem.File"  Processing File Collection  Processing File: C:\Build\Setup.Rul Done executing task "MSBuild.ExtensionPack.FileSystem.File".

Coordinator
Oct 29, 2010 at 9:40 AM

can you post your rule file

Coordinator
Oct 29, 2010 at 10:02 AM

I got it to work ok on a file that has 

#define DATE_STRING mike

in it.

According to my Regular Expression Scratchpad, your regex is doing this

^ (anchor to start of string)zero-width positive lookahead  . (any character)  * (zero or more times) (non-greedy)  #define  Word boundary between //w and //WEnd Capturezero-width positive lookahead  . (any character)  * (zero or more times) (non-greedy)  Any non-digit   ATE_STRING  Word boundary between //w and //WEnd Capture. (any character)* (zero or more times)$ (anchor to end of string)

 

Can you see if you get a match content with this tool.

Oct 29, 2010 at 5:12 PM
Edited Oct 29, 2010 at 9:31 PM

Yes, my expression is to find a line which contains a few key words. (Then I want to update that line).

I installed the application 'Regular expression Scratchpad' and it matched: ^(?=.*?\#define\b)(?=.*?\DATE_STRING\b).*$

 

Interpretation:

^ (anchor to start of string)zero-width positive lookahead  . (any character)  * (zero or more times) (non-greedy)  #define  Word boundary between //w and //WEnd Capturezero-width positive lookahead  . (any character)  * (zero or more times) (non-greedy)  Any non-digit   ATE_STRING  Word boundary between //w and //WEnd Capture. (any character)* (zero or more times)$ (anchor to end of string)

 

Change to:

<MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace"            

RegexPattern="^(?=.*?\#define\b)(?=.*?\DATE_STRING\b).*$" 

Replacement="#define DATE_STRING %27$(BuildDate_ddMMMyy)%27" 

        Files="@(SetUpRule)"             

       TextEncoding="utf-8"

/>

But it still is not replacing the value

 

Coordinator
Oct 29, 2010 at 5:15 PM

Please email me a sample file that doesn't work.

 

mike

Coordinator
Nov 1, 2010 at 5:22 PM

Resolved offline.

"

The problem is that you are not scanning across multiple lines.

You have two options.

  1. Drop the anchors (?=.*?\#define\b)(?=.*?\DATE_STRING\b).*
  2. Add multiline switch (?m:^(?=.*?\#define\b)(?=.*?\DATE_STRING\b).*$)

"