From 37e75ba0eaa8bd216397410fcba9f42ec1e86dc1 Mon Sep 17 00:00:00 2001 From: Adit Sheth Date: Wed, 2 Apr 2025 12:41:27 -0700 Subject: [PATCH 1/2] Fixed bug 45478. --- .../language-reference/compiler-directives.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/fsharp/language-reference/compiler-directives.md b/docs/fsharp/language-reference/compiler-directives.md index b467d5339cf6d..ab0d7c905b203 100644 --- a/docs/fsharp/language-reference/compiler-directives.md +++ b/docs/fsharp/language-reference/compiler-directives.md @@ -52,6 +52,27 @@ let str = "Debugging!" #endif ``` +### Automatically Defined Symbols + +The F# compiler automatically defines certain symbols based on the build configuration. These symbols can be used with `#if` directives for conditional compilation. + +| Symbol | Description | +|---------|-------------| +| `DEBUG` | Automatically defined in debug builds when compiling with the `Debug` configuration. | +| `TRACE` | Defined when tracing is enabled in the project settings. | + +For example, you can use these symbols in conditional compilation: + +```fsharp +#if DEBUG +printfn "Debugging mode is enabled." +#else +printfn "Release mode." +#endif +``` + +These symbols are typically set by the compiler and do not require explicit definition in the source code. + ## NULLABLE directive Starting with F# 9, you can enable nullable reference types in the project: From 1818a9c011f5ead9a7436709d01209be6daf1b3e Mon Sep 17 00:00:00 2001 From: Adit Sheth Date: Thu, 3 Apr 2025 14:30:09 -0700 Subject: [PATCH 2/2] More updates. --- .../language-reference/compiler-directives.md | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/fsharp/language-reference/compiler-directives.md b/docs/fsharp/language-reference/compiler-directives.md index ab0d7c905b203..6ffff291ca9c2 100644 --- a/docs/fsharp/language-reference/compiler-directives.md +++ b/docs/fsharp/language-reference/compiler-directives.md @@ -54,12 +54,30 @@ let str = "Debugging!" ### Automatically Defined Symbols -The F# compiler automatically defines certain symbols based on the build configuration. These symbols can be used with `#if` directives for conditional compilation. +In addition to symbols explicitly defined via project settings or command-line options, **F# projects inherit a set of predefined symbols** based on the SDK, target framework, and build configuration. -| Symbol | Description | -|---------|-------------| -| `DEBUG` | Automatically defined in debug builds when compiling with the `Debug` configuration. | -| `TRACE` | Defined when tracing is enabled in the project settings. | +#### Debug, Tracing, and Nullable Settings + +| Symbol | Description | +|-----------|-------------| +| `DEBUG` | Defined in debug builds when compiling with the `Debug` configuration. | +| `TRACE` | Defined when tracing is enabled in the project settings. | +| `NULLABLE` | Defined when `enable` is set in the project file. | + +#### Target Framework Symbols + +| Symbol | Description | +|--------|-------------| +| `NET`, `NETSTANDARD`, `NETCOREAPP` | General indicators of the .NET target type. | +| `NET5_0_OR_GREATER`, `NET6_0_OR_GREATER`, `NET7_0_OR_GREATER` | Defined for specific .NET versions. | +| `NETCOREAPP3_1_OR_GREATER`, `NETCOREAPP2_0_OR_GREATER` | Defined for .NET Core versions. | + +#### Build Configuration Symbols + +| Symbol | Description | +|-----------|-------------| +| `Release` | Defined in release builds. | +| `COMPILED` | Used in compiled projects. | For example, you can use these symbols in conditional compilation: @@ -71,7 +89,8 @@ printfn "Release mode." #endif ``` -These symbols are typically set by the compiler and do not require explicit definition in the source code. +For a full list of predefined symbols, refer to the official documentation: +[.NET SDK Predefined Compilation Symbols](https://learn.microsoft.com/dotnet/fsharp/tools/fsharp-interactive/#interactive-and-compiled-preprocessor-directives). ## NULLABLE directive