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

天大地大妈咪最大 提交于 2019-12-01 19:38:11

问题


I saw a video on https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-F-Tools where a project using Suave is created. I tried to follow exactly what was being done but my installation of VS 2017, just updated today, behaves quite differently.

First I installed Suave exactly like in the video, and it appears among my references, between mscorlib and System, just like in the video.

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. I copied the same code in my editor, in the file 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. (Maybe that is because I am using Community Edition?)

In any case, I added open Suave to the code so I had:

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."

If I right-click on Suave in the Solution Explorer and then choose "Send to Interactive" then I can open Suave in F# Interactive.

I can install and use other packages like Deedle with no problems.

Any ideas on what is wrong?


回答1:


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. It's actually 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)
  2. Target F# 4.1
  3. Nuget Suave

Add this point nuget will download FSharp.Core and replace it in your project. That's not very nice.

  1. Delete FSharp.Core from your references
  2. From Nuget add FSharp.Core 4.1

You're good to go:

I also suggest you install Paket for VS2017. You can then access it from the Tools menu in 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. If you're using a lot of fsx files, this is extra nice because paket will strip out the version numbers from the path. Please look at the paket.dependencies and paket.references file in the solution on GitHub:

paket.dependencies in solution root:

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

nuget Suave

paket.references in project folder:

Suave
FSharp.Core


来源:https://stackoverflow.com/questions/43460879/why-cant-i-get-suave-to-work-on-vs-2017

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!