I always find it amazingly hard to tweak .NET project's tooling
outside Visual Studio or Rider. The solution (.sln
) file is just a
cryptic list of GUIDs, project files (.[fc]proj
) have no
autocompletion on its options through LSPs and there's nothing fancy
on fsharp-mode nor VSCode Extensions to help you. For this reason I
want to show here some files and options I use to make my F#/C#
projects safer and easier to use.
According to the documentation, Directory.Build.props
is a file that
you can put at the root of your directory to define default properties
to all of your project at once. In my case, I use it with the
following properties:
<Project>
<PropertyGroup>
<Deterministic>true</Deterministic>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
</PropertyGroup>
</Project>
-
TreatWarningsAsErrors: This will make all warning raise errors. My main goal with this is to avoid FS0025, for some reason incomplete pattern matching in F# does not raise an error by default.
-
MSBuildTreatWarningAsErrors: This makes compilation/build warnings raise errors. I always had problems with FSharp.Core versions mismatching some dependency versions, this way I won't see this mismatch again until I solve it.
-
Deterministic: As the name implies, this will force the compiler to output identical assemblies given the same inputs.