How-To's

Rider 2018.1 brings file ordering to F# projects

The latest build of Rider 2018.1 EAP brings joy to F# developers by adding file ordering to F# projects! Files are now ordered in dependency order, and we can drag-and-drop to reorder files in our project. Let’s have a look!

File ordering for F# in Rider

The F# compiler, when invoked using MSBuild, will determine file order based on <Compile> entries in our .fsproj file (which is just like any other project file). The latest Rider 2018.1 EAP will display files in our project in the same order. We can also re-order files in F# projects, helping us structure our project.

In the Solution Explorer, we can drag-and-drop F# files (click and hold, drag the mouse), and control the file order that will be observed by MSBuild and the compiler:

Ordering FSharp files in Rider Solution Explorer

File re-ordering not only works for single files, it works for multiple files as well! Note we can also move files before or after an existing directory.

Ordering multiple files in an FSharp project

Why file (and code) ordering matters in F#

For developers coming from other .NET languages, like C#, working with F# projects can be a bit confusing at first. While in C# we can organize our code in namespaces and in classes, the F# compiler requires files (and code within a file) to be organized “in order”. We can not use forward references to code that hasn’t been seen by the compiler yet.

Let’s explain this using an object oriented concept. We can write a Person class that has a property of type Address. One will be in Person.cs, the other in Address.cs. In C#, the order of files would not matter, while in F# our Address class will have to be defined before our Person class, or compilation will fail.

Starting with F# 4.1, we can use the module rec keyword in a module or namespace to allow unordered code within, but in general having support for re-ordering files in F# projects will help us successfully work with our projects.

We’d love to hear your feedback on F# file re-ordering! Give the latest Rider 2018.1 EAP build a try!

image description