You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/fsharp/language-reference/compiler-directives.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,58 @@ There is no `#define` compiler directive in F#. You must use the compiler option
53
53
54
54
Conditional compilation directives can be nested. Indentation is not significant for compiler directives.
55
55
56
+
## Predefined symbols
57
+
58
+
The F# compiler and build system automatically define several symbols that can be used for conditional compilation.
59
+
60
+
### Build configuration symbols
61
+
62
+
The following symbols are defined based on your build configuration:
63
+
64
+
-`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).
65
+
-`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.
66
+
67
+
You can override these values using the [`-define` compiler option](compiler-options.md) or project settings.
68
+
69
+
### Compilation mode symbols
70
+
71
+
The following symbols distinguish between different compilation modes:
72
+
73
+
-`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.
74
+
-`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.
75
+
76
+
For more information about using these symbols in scripts, see [Interactive Programming with F#](../tools/fsharp-interactive/index.md).
77
+
78
+
Example:
79
+
80
+
```fsharp
81
+
#if INTERACTIVE
82
+
// Code specific to F# Interactive
83
+
#r "nuget: Newtonsoft.Json"
84
+
#endif
85
+
86
+
#if COMPILED
87
+
// Code specific to compiled assemblies
88
+
open System.Configuration
89
+
#endif
90
+
```
91
+
92
+
### Target framework symbols
93
+
94
+
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.
0 commit comments