Skip to content

Instantly share code, notes, and snippets.

@TheAngryByrd
Last active December 16, 2025 14:55
Show Gist options
  • Select an option

  • Save TheAngryByrd/2947554db4d4348a9a445cadb2725e10 to your computer and use it in GitHub Desktop.

Select an option

Save TheAngryByrd/2947554db4d4348a9a445cadb2725e10 to your computer and use it in GitHub Desktop.
Showing different runtime values
 dotnet run -f net8.0
Hello from F#
IFDEF: This is .NET 8.0
Assembly: .NETCoreApp,Version=v8.0
System DLL: 8.0.0.0

After setting RollForward

Hello from F#
IFDEF: This is .NET 8.0
Assembly: .NETCoreApp,Version=v8.0
System DLL: 10.0.0.0
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<RootNamespace>different_tfms</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
</Project>
let ifDefRuntime =
#if NET8_0
"This is .NET 8.0"
#endif
#if NET9_0
"This is .NET 9.0"
#endif
#if NET10_0
"This is .NET 10.0"
#endif
let assemblyRuntime =
System.Reflection.Assembly
.GetExecutingAssembly()
.GetCustomAttributes(typeof<System.Runtime.Versioning.TargetFrameworkAttribute>, false)
|> Seq.cast<System.Runtime.Versioning.TargetFrameworkAttribute>
|> Seq.head
|> fun attr -> attr.FrameworkName
let systemDllVersion =
typeof<System.String>
.Assembly
.GetName()
.Version
|> string
// For more information see https://aka.ms/fsharp-console-apps
printfn $"Hello from F#"
printfn $"IFDEF: {ifDefRuntime}"
printfn $"Assembly: {assemblyRuntime}"
printfn $"System DLL: {systemDllVersion}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment