From 44cd225f9fef7582716cb89132e718935eac4afa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Oct 2025 13:48:42 +0000 Subject: [PATCH 1/3] Initial plan From baa08580ed8189cdfc74247edae9b3268ee2df22 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Oct 2025 13:56:24 +0000 Subject: [PATCH 2/3] Add predefined compiler symbols documentation Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- .../language-reference/compiler-directives.md | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/docs/fsharp/language-reference/compiler-directives.md b/docs/fsharp/language-reference/compiler-directives.md index 585478b98e0bc..ace7446401bfa 100644 --- a/docs/fsharp/language-reference/compiler-directives.md +++ b/docs/fsharp/language-reference/compiler-directives.md @@ -53,6 +53,58 @@ There is no `#define` compiler directive in F#. You must use the compiler option Conditional compilation directives can be nested. Indentation is not significant for compiler directives. +## Predefined symbols + +The F# compiler and build system automatically define several symbols that can be used for conditional compilation. + +### Build configuration symbols + +The following symbols are defined based on your build configuration: + +- `DEBUG`: Defined when compiling in Debug mode. In the project system, the `DEBUG` symbol is automatically defined in the Debug configuration, but not in the Release configuration. This symbol is commonly used with assertions and diagnostic code. For more information, see [Assertions](assertions.md). +- `TRACE`: Defined for builds that enable tracing. Like `DEBUG`, this symbol is typically defined in Debug configurations but can also be enabled in Release configurations. + +You can override these values using the [`-define` compiler option](compiler-options.md) or project settings. + +### Compilation mode symbols + +The following symbols distinguish between different compilation modes: + +- `COMPILED`: Defined when compiling code with the F# compiler. This symbol is useful when you need code to behave differently in compiled assemblies versus F# Interactive sessions. +- `INTERACTIVE`: Defined when compiling or executing code in F# Interactive (`dotnet fsi`), including both interactive sessions and script execution. This allows you to write code that works differently when running interactively. + +For more information about using these symbols in scripts, see [Interactive Programming with F#](../tools/fsharp-interactive/index.md). + +Example: + +```fsharp +#if INTERACTIVE +// Code specific to F# Interactive +#r "nuget: Newtonsoft.Json" +#endif + +#if COMPILED +// Code specific to compiled assemblies +open System.Configuration +#endif +``` + +### Target framework symbols + +The build system also defines preprocessor symbols for different target frameworks in SDK-style projects. These symbols are useful when creating libraries or applications that target multiple .NET versions. + +[!INCLUDE [Preprocessor symbols](~/includes/preprocessor-symbols.md)] + +For example, you can use these symbols to conditionally compile code based on the target framework: + +```fsharp +#if NET6_0_OR_GREATER +// Use .NET 6+ specific APIs +#else +// Use alternative implementation for older frameworks +#endif +``` + ## NULLABLE directive Starting with F# 9, you can enable nullable reference types in the project: From 976432a643364bdd0a1b97eac8a48db603bd9d7c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Oct 2025 13:57:25 +0000 Subject: [PATCH 3/3] Add ai-usage frontmatter and update ms.date Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/fsharp/language-reference/compiler-directives.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/fsharp/language-reference/compiler-directives.md b/docs/fsharp/language-reference/compiler-directives.md index ace7446401bfa..38169df1c1d64 100644 --- a/docs/fsharp/language-reference/compiler-directives.md +++ b/docs/fsharp/language-reference/compiler-directives.md @@ -1,9 +1,10 @@ --- title: Compiler Directives description: Learn about F# language conditional compilation directives, line directives, and warn directives. -ms.date: 12/10/2018 +ms.date: 10/21/2025 f1_keywords: - "#endif_FS" +ai-usage: ai-assisted --- # Compiler Directives