我正在尝试在 Mac 上使用 F# 并使用一个非常简单的脚本时遇到问题。我正在遵循这个教程,但是它在 results.Descendants ["a"] 处中断。
有趣的是,VS 将 .Descendants 识别为 results 的有效方法,但在运行时(仅尝试不带参数的 Descendants)时,我会得到:
似乎 FSharp.Data 只被部分导入了或者说有问题。有趣的是,HtmlDocument 能够工作,但扩展却不行。
有什么想法可以解决这个问题吗?
编辑:代码
有趣的是,VS 将 .Descendants 识别为 results 的有效方法,但在运行时(仅尝试不带参数的 Descendants)时,我会得到:
error CS1061: 'HtmlDocument' does not contain a definition for 'Descendants' and no
extension method 'Descendants' accepting a first argument of type 'HtmlDocument' could
be found (are you missing a using directive or an assembly reference?)
似乎 FSharp.Data 只被部分导入了或者说有问题。有趣的是,HtmlDocument 能够工作,但扩展却不行。
有什么想法可以解决这个问题吗?
编辑:代码
// Learn more about F# at http://fsharp.org
open System
open FSharp.Data
[<EntryPoint>]
let main argv =
let results = HtmlDocument.Load("http://www.google.co.uk/search?q=FSharp.Data")
let links =
results.Descendants "a"
|> Seq.choose (fun x ->
x.TryGetAttribute("href")
|> Option.map (fun a -> x.InnerText(), a.Value())
)
0 // return an integer exit code
编辑2: 我手动使用NuGet下载了FSharp.Data,现在我可以在fsharpi中运行下面的脚本。我不知道这和Visual Studio做什么有什么区别?
#r "./FSharp.Data.2.4.6/lib/net45/FSharp.Data.dll"
open FSharp.Data
let results = HtmlDocument.Load("http://www.google.co.uk/search?q=FSharp.Data")
let d= results.Descendants "a"
第三次编辑:在fsharpi和vs中运行的区别:
- fsharpi使用mono,而VS使用dotnet(即.net core 2)
- nuget下载了FSharp.Core 4.0.0.1,而VS使用的是4.3.4
我似乎无法让VS使用FSharp.Core 4.0.0.1。即使我添加了特定版本,它仍然使用4.3.4。