United Kingdom: +44 (0)208 088 8978

The CIT Console App Template

Isaac takes us through a new opinionated .NET template for F# applications.

We're hiring Software Developers

Click here to find out more

The .NET SDK comes with a templating system that can be used to create new applications based on a pre-defined coding scaffold. The template system is extensible, meaning you can create your own templates as well (this is also the approach used for the SAFE Stack).

A new F# Console Application template

The basic .NET console application template (dotnet new console) is fine for getting started with something quickly, but it misses several things that a .NET developer will typically want - and especially an F# developer. Therefore we've released our own console application template - an opinionated template which contains many things that you will typically want when creating a new application.

To install the CIT Console template, execute the following in a terminal:

dotnet new install CompositionalIT.Console

You can then create a new CIT Console as follows:

dotnet new cit-app

This will create a standard F# console application except it also contains the following:

  • A global.json file, pinned to .NET 8. This file explicitly states what version of .NET you're using, so if someone else accesses this code and has an older version of the framework, you'll get a nice error message saying what version of .NET you need to install.
  • Basic VS Code settings to hide inlay hints by default. Inlay hints are very useful, but they can sometimes be a little intrusive. The settings this template ships with turn them off by default but allow you to temporarily turn them back on using a keypress combination.
  • A .gitignore file with common F# settings. This prevents you from accidentally committing e.g. bin and obj folders into your git repository.
  • Fantomas v6 installed as a local tool. Fantomas is the standard code formatter for F# and we believe all new projects should use it. The template also ships with an Editor Config file which configures some behaviours of Fantomas per our recommendations.
  • Paket for dependency management. Whilst NuGet has improved greatly in recent years, we still recommend the use of Paket over it for its superior dependency management capabilities. We also ship two packages that we feel are used in many projects these days: FSharp.Core (obvious) and FsToolkit.ErrorHandling - an excellent package that provides useful computation expressions and combinators for working with Options and Results.

One final change we've made with this template is to place the application in a src/<project> folder structure and create a top-level solution file. Whilst for single project applications this may feel a little overkill, we feel that it puts you in a better place if and when you decide you need to create secondary projects within the solution.

Contributing

If you're interested in finding out more about this template (or contributing!) you can find the source code here. As you will no doubt see, at its most basic a .NET template is little more than a Content folder which contains the code to "generate", plus a few files required for packaging into a NuGet template.

Summary

The default F# console application is a great way to start experimenting with running applications in F#. However, it does not contain many of the core tools and files that you will require for a full-blown F# application. The CIT Console template contains those assets that we feel are commonly required and will be especially useful for those of us who may not have the experience to know in advance how to use them.

As always, we'd love your feedback on this - please feel free to raise issues on the template!