我正在使用XMLHelper.XMLRead以假脚本读取XML文件,但它正在抛出一个错误,即
The type '(string -> string ->seq<string>)' is not a type whose value can be enumerated with this syantax , i.e. is not compatible with either seq<_>,IEnumerable<_> or IEnumerable and does not have a GetEnumerator method
下面是我的代码:
let x = XMLHelper.XMLRead true "D:/test/Version.Config" "/version/major/minor"
Target "New" (fun _ ->
for i in x do
printf "%s" i
)发布于 2017-03-21 07:01:00
如果查看XMLHelper,您将看到XMLRead的函数签名如下所示:
failOnError:bool -> xmlFileName:string -> nameSpace:string -> prefix:string -> xPath:string -> seq<string>看起来您在指定failOnError、xmlFileName和nameSpace参数*,但没有指定最后两个字符串参数。因为F#使用部分适用,这意味着您从XMLRead调用中得到的是一个正在等待另外两个字符串参数的函数(因此您得到的错误消息中的string -> string -> (result)函数签名)。
*您可能打算让"/version/major/minor"填充xPath参数,但是F#按给定的顺序应用参数,因此它填充了第三个参数,即nameSpace。
要解决这个问题,请指定XMLRead所期望的所有参数。我已经查看了XMLRead源代码,如果您在输入文档中没有使用XMLRead空间,那么nameSpace和prefix参数应该是空字符串。你想要的是:
let x = XMLHelper.XMLRead true "D:/test/Version.Config" "" "" "/version/major/minor"
Target "New" (fun _ ->
for i in x do
printf "%s" i
)顺便说一句,现在我已经看过你的另一个问题了,我认为您需要XMLHelper.XMLRead_Int函数:
let minorVersion =
match XMLHelper.XMLRead_Int true "D:/test/Version.Config" "" "" "/version/major/minor" with
| true, v -> v
| false, _ -> failwith "Minor version should have been an int"一旦您的代码通过了这一行,要么您在minorVersion中有一个int,要么您的构建脚本抛出一个错误并退出以便您可以修复您的Version.Config文件。
https://stackoverflow.com/questions/42919797
复制相似问题