Sunday, December 10, 2017

[ADVENT 2017] Current state of F# 4.x tooling and IDE ecosystem on December 2017

Hi my dear blog readers!

Thanks to Sergey Tihon for organizing this community-driven advent blog gathering in this year-end of 2017!

sergey_tihon_advent2017

So here we are, on the edge of 2017. There are lots of advances in F# toolings and ecosystem, including the nature of open source ecosystem that has been available since the beginning of F# in VS 2010. When I say F# toolings. I’m not limiting myself to F# tooling in Visual Studio. Toolings in my context is tooling in Visual Studio, Visual Studio Code, and new contender/competitor of Visual Studio IDE, Jetbrains Rider.

F# state

Most advances in F# itself are without IDE. These are the current state of F# itself:

  1. F# supports .NET Core 2.0/.NET Standard 2.0 TFM development. This is also in sync with tooling support, starting with VS 2017 15.5.0, but I suggest you to install 15.5.1 update. (Please read my notes below)
  2. F# implements async interop with C#/VB async correctly, especially those xxxTask function such as Async.StartAsTask. See https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes#fsharp
  3. F# now supports goto definition correctly. I know this is quite IDE-related, but it needs some reworks on existing F# compiler. Thanks to relentless community support of F# contributors, especially Saul and Vasily Kirichenko. These are the PRs related to “go to definition” works: https://github.com/Microsoft/visualfsharp/pulls?q=is%3Apr+%22go+to+definition%22+is%3Aclosed 
  4. Also now goto definition can go from F# to C#/VB.

Now, at F# IDE support:

  1. Ionide (Visual Studio Code extension for F#) gets nice updates! One of the notable feature is automatic project reloading, especially when dealing with F#/.NET Core 2.0 project. This is the latest release notes of Ionide: https://github.com/ionide/ionide-vscode-fsharp/blob/master/RELEASE_NOTES.md
  2. Jetbrains Rider (visual Studio competitor) has provided support for F#. Still, many works need to be done in .NET Core 2.0 full support. Read the original announcement of F# support here: https://blog.jetbrains.com/dotnet/2017/05/08/rider-is-now-also-an-fsharp-ide-adding-fsharp-support/
  3. In Visual Studio 2017 15.5.0: on the installation of a Workload that requires .NET Core 2.0, it will also install F# language support by default. The .NET Core, ASP.NET, and Azure workloads now do this.

Therefore, if you use Visual Studio 2017, it is highly recommended to update or directly use at least 15.5.0 update instead.

NOTE on Visual Studio 2017 15.5.0:

There’s one catch: if you use Xamarin in your worload, the 15.5.0 update on previous version will somehow override Xamarin MonoDroid VSIX packages. Fortunately, on 7th December, there is a fresh maintenance update on 15.5.0, the 15.5.1. This 15.5.1 provides the Xamarin package issue.

Now let’s meet F# and .NET Core using command prompt and in Visual Studio!


F# <3 .NET Core

Now, let’s try F# support for .NET Core.

We could check F# support availability as template, within the .NET Core tool of dotnet.

Using dotnet’s CLI tool, we can display list of templates installed in our .NET Core 2.0 SDK by using new command (parameter that acts as command to execute further) with –l for parameter of new:

dotnet new –l

On .NET Core SDK 2.0.3, run the dotnet above and we will have this list:

dotnet_sdk_203_new

Let’s just focus on Short Name and the Language section on the list:

dotnet_sdk_203_new_languages

So we can compose and create any kinds of project that has F# as language support. The Short Name will be used as new parameter to define what template we’re going to use, the language parameter define the used language.

For example, we can create .NET Core console app with F#:

dotnet new console -n HelloFSharp -lang F#

NOTE: we should use -name parameter to give name to our project, instead of having default name from the template.

Run that in command prompt, we will have the creation of F# .NET Core 2.0 console project:

dotnet_new_console_fsharp

Now let’s look at the content of Program.fs:


// Learn more about F# at http://fsharp.org

open System

[]
let main argv =
    printfn "Hello World from F#!"
    0 // return an integer exit code

Yes, it’s the same as our good old .NET Framework’s F# Console template from VS 2010/2012/2013/2015!

Then we can run it:

dotnet_run_fsharp

We can also provide more granular TFM as the target framework, but this option is only available for classlib template, not for console project template.

For more information, please visit dotnet new docs page: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new?tabs=netcore2x

What about Visual Studio 2017?

In Visual Studio 2017 starting from 15.5.0, we now have this:

VS2017_FS_template

YES! We now have F# .NET Core 2.0 fsproj support within Visual Studio 2017!

What are you waiting for? Go code in F# now!

2 comments:

  1. RE: "F# now supports goto definition correctly."

    I was quite excited to read this and I updated to VS 15.5.2, but unfortunately I get the same error as always.

    namespace Library1

    open System.Text

    type Class1() =
    let sb = new StringBuilder()
    member this.X =
    // F12 should show me StringBuilder metadata including other overloads, but
    // instead 'Cannot navigate to the symbol under the caret'.
    sb.AppendLine("Yes") |> ignore
    "F#"

    Is it just me, or is this feature not actually in VS yet?

    ReplyDelete
    Replies
    1. That feature isn't available yet in VS 2017 15.5. It is available in VS 2017 15.7.x and later.

      Delete