简体   繁体   English

为什么会出现F#错误FS0039:未定义名称空间或模块'Http'

[英]Why am I getting F# error FS0039: The namespace or module 'Http' is not defined

In Visual Studio 2015 and 2017, I'm trying out the Http class from several F# examples in FSharp Interactive, and I keep getting: 在Visual Studio 2015和2017中,我正在FSharp Interactive的几个F#示例中尝试Http类,并且不断得到:

error FS0039: The namespace or module 'Http' is not defined 错误FS0039:未定义名称空间或模块'Http'

Here's the sample: 这是示例:

open FSharp.Data
let response = Http.RequestString("http://api.themoviedb.org/3/search/movie", silentHttpErrors = true)

This is clearly due to the version of FSharp.Data. 这显然是由于FSharp.Data的版本。 Is there a way to specify the correct version for FSharp Interactive? 有没有办法为FSharp Interactive指定正确的版本? What version of FSharp.Data contains the Http module? 哪个版本的FSharp.Data包含Http模块?

Based on the comments, I put together a script to install Paket, intitialise it and then optionally install the dependencies whenever the script was run. 根据评论,我整理了一个脚本来安装Paket,对其进行初始化,然后在运行脚本时有选择地安装依赖项。

/// install.paket.fsx
open System
open System.IO

printfn "Initialising..."
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
// invisibly run a command (paket.exe in this case)
let init paket =
    let psi = new System.Diagnostics.ProcessStartInfo(paket)
    psi.Arguments <- "init"
    psi.UseShellExecute <- false
    let p = System.Diagnostics.Process.Start(psi)
    p.WaitForExit()
    p.ExitCode

if not (File.Exists "paket.exe") then
    printfn "installing paket"
    let url = "http://fsprojects.github.io/Paket/stable"
    use wc = new Net.WebClient()
    let tmp = Path.GetTempFileName()
    let stable = wc.DownloadString(url)
    wc.DownloadFile(stable, tmp)
    File.Move(tmp,Path.GetFileName stable)
    printfn "paket installed"
    System.Threading.Thread.Sleep(100)
    printfn "initialising paket"
    init "paket.exe" |> ignore
    System.Threading.Thread.Sleep(200)
    printfn "paket initialised"
else
    printfn "paket already exists"

/// install.dependencies.fsx

open System.IO
printfn "Installing dependencies"
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
#r "paket.exe"

open Paket
let dependencies = Paket.Dependencies.Locate(__SOURCE_DIRECTORY__)

printfn "%s" dependencies.DependenciesFile

if not (File.Exists "packages/Newtonsoft.Json/lib/net40/Newtonsoft.Json.dll") then
    printfn "installing nuget depenencies"
    // either use the dependencies.Install to add dependencies in the paket.dependencies file
    //dependencies.Install true |> ignore
    // or install them by name
    // I remove the existing versions
    dependencies.Remove "FSharp.Data"
    dependencies.Remove "Newtonsoft.Json 8.0.3"
    // then add them (because I'm pedantic about the way the dependencies file looks)
    dependencies.Add "FSharp.Data"
    dependencies.Add "Newtonsoft.Json 8.0.3"
    printfn "nuget depenencies installed"
else
    printfn "nuget depenencies already exist"

printfn "Dependencies installed"

Note the use of 8.0.3 for Newtonsoft.Json, The latest version brings over 20 additional dependencies, so I've found a nice old version that's very self contained. 请注意,Newtonsoft.Json使用8.0.3,最新版本带来了20多个附加依赖项,因此我发现了一个很好的旧版本,该版本非常自包含。 You may leave the version number out if you want the latest. 如果需要最新版本,可以省略版本号。

Then, I use these scripts in a shared utilities.fsx for reusable functionality 然后,我在共享的Utility.fsx中使用这些脚本来实现可重用的功能

System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
#load "install.paket.fsx"
#load "install.dependencies.fsx"

#r "packages/fsharp.data/lib/net40/fsharp.data.dll"
#r "packages/Newtonsoft.Json/lib/net40/Newtonsoft.Json.dll"

open FSharp.Data
open FSharp.Data.HtmlAttribute
open FSharp.Data.HtmlNode
open FSharp.Data.HttpRequestHeaders
open Newtonsoft.Json
open System.Net
open System.IO
// utilities like authentication, Http requests and JSON (de)serialization

Finally, I reference the whole lot in my target script by just loading utilities: 最后,通过加载实用程序,我在目标脚本中引用了很多内容:

System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
#load "utilities.fsx"
open Utilities

which takes care of all the dependencies. 照顾所有的依赖。 These can be run from Visual studio with the Alt + Enter key combination or from the command line with fsi.exe MyScript.fsx 这些可以从Visual Studio中使用Alt + Enter键组合来运行,也可以从命令行中使用fsi.exe MyScript.fsx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 F#错误&#39;错误FS0039:未定义名称空间或模块&#39;MySql&#39;? - F# error 'error FS0039: The namespace or module 'MySql' is not defined'? F#错误FS0039:未定义类型&#39;XmlProvider&#39; - F# error FS0039: The type 'XmlProvider' is not defined F# 错误 FS0039:未定义值或构造函数“输入” - F# error FS0039: The value or constructor 'input' is not defined 使用F#查询表达式时收到此消息:错误FS0039:未定义值或构造函数“查询” - I got this msg while using F# query expression : error FS0039: Undefined value or constructor “query” F# CsvProvider can't find member in Row error FS0039 - F# CsvProvider cant find member in Row error FS0039 为什么我在 class 未定义的参数中收到错误提示 function - 错误 FS0039:值或构造函数“函数”未定义 - Why I get error saying function in argument for a class not defined - error FS0039: The value or constructor 'function' is not defined 错误FS0039:未定义字段,构造函数或成员&#39;X&#39; - error FS0039: The field, constructor or member 'X' is not defined 为什么在错误 FS0039 The type &#39;JsonProvider&#39; is not defined 时程序仍在运行? - Why is the program still running while Error FS0039 The type 'JsonProvider' is not defined? XmlProvider FS0039中的DomainTypes未定义 - DomainTypes in XmlProvider FS0039 not defined F#模块/命名空间错误 - F# Module/Namespace Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM