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?
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.
- Set the project to .NET 4.6.2 (or whatever you fancy)
- Target F# 4.1
- Nuget Suave
Add this point nuget will download FSharp.Core and replace it in your project. That's not very nice.
- Delete FSharp.Core from your references
- 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