简体   繁体   中英

Changin text in a file using RegexReplaceInFilesWithEncoding gives an error - FAKE F#MAKE

I am trying to change text in a file in FAKE code using a predefined function RegexReplaceInFilesWithEncoding . But it is throwing an error .... ie The value is not a function and can not be applied . below is my code :

Note: version_no is dynamic , but for the time being I am using it as static.

#r "./packages/FAKE/tools/FakeLib.dll"
open Fake

let version_no = "0.65"

Target "ChangeText" (fun _ ->
    !! "D:/test/TestFile.txt"
    |> RegexReplaceInFilesWithEncoding @"admintool: XYZ.XYZ.XYZ_0.[0-9][09]"
                                       @"admintool: XYZ.XYZ.XYZ_"+version_no
                                       System.Text.Encoding.UTF8)

"ChangeText"
RunTargetOrDefault "ChangeText"

In F#, function application has the highest precedence of all operations. That includes the "plus" operator.

This means that code like this:

f x+5

Will be interpreted like this:

(f x) + 5

The application of f to x comes first, because it has the highest precedence, and the + 5 part comes after.

To fix this, just add parentheses around the operation:

f (x+5)

Or, applying this to your case:

Target "ChangeText" (fun _ ->
    !! "D:/test/TestFile.txt"
    |> RegexReplaceInFilesWithEncoding @"admintool: XYZ.XYZ.XYZ_0.[0-9][09]"
                                       (@"admintool: XYZ.XYZ.XYZ_"+version_no)
                                       System.Text.Encoding.UTF8)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM