Hi my dear blog readers!
Thanks to Sergey Tihon for organizing this community-driven advent blog gathering in this year-end of 2017!
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:
- 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)
- 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
- 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
- Also now goto definition can go from F# to C#/VB.
Now, at F# IDE support:
- 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
- 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/
- 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:
Let’s just focus on Short Name and the Language section on the list:
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:
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:
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:
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!