简体   繁体   English

为什么我不能让Suave在VS 2017上工作?

[英]Why can't I get Suave to work on VS 2017?

I saw a video on https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-F-Tools where a project using Suave is created. 我在https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-F-Tools上看到了一个视频,其中创建了一个使用Suave的项目。 I tried to follow exactly what was being done but my installation of VS 2017, just updated today, behaves quite differently. 我试着完全遵循正在做的事情但是我今天更新的VS 2017的安装表现完全不同。

First I installed Suave exactly like in the video, and it appears among my references, between mscorlib and System , just like in the video. 首先,我在视频中安装Suave,就像在视频中一样,它出现在我的参考文献中,介于mscorlibSystem之间。

Then the video shows the following code: 然后视频显示以下代码:

[<EntryPoint>]
let main argv = 
    startWebServer
    0 // return an integer exit code

At this point VS 2017 suggests "Open Suave" in the video, since startWebServer is not recognized. 此时VS 2017在视频中提示“Open Suave”,因为无法识别startWebServer。 I copied the same code in my editor, in the file Program.fs . 我在编辑器中的Program.fs文件中复制了相同的代码。 There is an error message "The value or constructor 'startWebServer' is not defined" but there are no suggestions when the cursor hovers on the left yellow area. 有一条错误消息“未定义值或构造函数'startWebServer'”但是当光标悬停在左侧黄色区域时没有任何建议。 (Maybe that is because I am using Community Edition?) (也许那是因为我使用的是Community Edition?)

In any case, I added open Suave to the code so I had: 无论如何,我在代码中添加了open Suave ,所以我有:

open Suave

[<EntryPoint>]
let main argv = 
    startWebServer
    0 // return an integer exit code

At this point I get a red squiggle under Suave and the error message "The namespace or module 'Suave' is not defined." 此时我在Suave下出现红色波形,并且错误消息“未定义名称空间或模块'Suave'。”

If I right-click on Suave in the Solution Explorer and then choose "Send to Interactive" then I can open Suave in F# Interactive. 如果我在解决方案资源管理器中右键单击Suave然后选择“发送到交互式”,那么我可以在F#Interactive中打开Suave

I can install and use other packages like Deedle with no problems. 我可以安装和使用像Deedle这样的其他软件包没有问题。

Any ideas on what is wrong? 关于什么是错的任何想法?

Of course, you can but it might be just a little work: 当然,你可以,但它可能只是一点点工作:

在此输入图像描述

You should be able to clone my repo if necessary. 如有必要,您应该可以克隆我的仓库 You will note that my fsprojects file does not reference an explicit version of FSharp.Core so there is no confusion between the Target and actual version. 您会注意到我的fsprojects文件没有引用FSharp.Core的显式版本,因此Target和实际版本之间没有混淆。 It's actually FSharp.Core 4.1 btw. 它实际上是FSharp.Core 4.1 btw。

If you're working from your original solution I would make a new one first. 如果您使用原始解决方案,我会先制作一个新解决方案。

  1. Set the project to .NET 4.6.2 (or whatever you fancy) 将项目设置为.NET 4.6.2(或您喜欢的任何东西)
  2. Target F# 4.1 目标F#4.1
  3. Nuget Suave Nuget Suave

Add this point nuget will download FSharp.Core and replace it in your project. 添加此点nuget将下载FSharp.Core并将其替换为您的项目。 That's not very nice. 那样不是很好。

  1. Delete FSharp.Core from your references 从引用中删除FSharp.Core
  2. From Nuget add FSharp.Core 4.1 从Nuget添加FSharp.Core 4.1

You're good to go: 你很高兴去:

在此输入图像描述

I also suggest you install Paket for VS2017. 我还建议您安装Paket for VS2017。 You can then access it from the Tools menu in VS. 然后,您可以从VS中的“工具”菜单访问它。 That way you can just add Suave and FSharp.core to your paket.references and dependencies file, set redirects: on , run Paket install from the menu and forget about all this version mismatch business. 这样你就可以将Suave和FSharp.core添加到你的paket.references和dependencies文件中,设置redirects: on ,从菜单中运行Paket install并忘记所有这些版本不匹配的业务。 If you're using a lot of fsx files, this is extra nice because paket will strip out the version numbers from the path. 如果您使用了大量的fsx文件,这是非常好的,因为paket将从路径中删除版本号。 Please look at the paket.dependencies and paket.references file in the solution on GitHub: 请查看GitHub上解决方案中的paket.dependencies和paket.references文件:

paket.dependencies in solution root: 解决方案根目录中的paket.dependencies:

framework: = net462
source https://www.nuget.org/api/v2
redirects: on

nuget Suave

paket.references in project folder: 项目文件夹中的paket.references:

Suave
FSharp.Core

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

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