I recently needed to supply two variations of an algorithm in an F# source file – one for .NET 3.5 consumers and another for .NET 4.0 consumers (the later framework version allows parallel execution using the FSharp.Collections.ParallelSeq). One way is to tell msbuild to reference the library, conditional on the version of the .NET framework – and also, define a constant which can be used within the source code to choose the algorithm.
In msbuild, define a constant according to the framework
<PropertyGroup Condition=" '$Framework' == 'NET35' "> <DefineConstants>NET35</DefineConstants> </PropertyGroup> <PropertyGroup Condition=" '$Framework' == 'NET40' "> <DefineConstants>NET40</DefineConstants> </PropertyGroup>
In msbuild, reference library if .NET 4.0
<ItemGroup Condition=" '$Framework' == 'NET40' "> <Reference Include="FSharp.Collections.ParallelSeq"/> </ItemGroup>
Specify conditional compilation directives in the source code
let doMapping = ... // some transformation #if NET35 items |> Seq.map doMapping #else items |> FSharp.Collections.ParallelSeq.PSeq.map doMapping