A magic command is a scriptable shortcut to a more complex behavior. The magic command concept is familiar to Jupyter users. With a slight change in syntax to accommodate the .NET languages, they're also available in .NET Interactive.
Magic commands must always occur at the beginning of a line and are prefixed with either #! or, less commonly, #. The latter occurs only when unifying behaviors with language-specific compiler directives such as #r, a compiler directive that's implemented in both C# and F# script. Another difference from Jupyter's magic commands is that in .NET Interactive there is no distinction between a "cell magic" and a "line magic".
Here's an example using the #!time magic command:
Magic commands use a command line-style syntax, including options and arguments similar to a command line tool. For every magic command, you can get help using -h:
The following is a list of magic commands supported by .NET Interactive:
The following magic commands are available globally.
| Command | Behavior |
|---|---|
#!csharp (also: #!c#, #!C#) |
Indicates that the code that follows is C#. Specifically, it is the C# scripting dialect. |
#!fsharp (also: #!f#, #!F#) |
Indicates that the code that follows is F#. |
#!pwsh (also: #!powershell) |
Indicates that the code that follows is PowerShell. |
#!javascript (also: #!js) |
Indicates that the code that follows is JavaScript, to be executed in the browser. |
#!html |
Indicates that the code that follows is HTML, which can then be directly rendered in the browser. |
#!lsmagic |
Lists the available magic commands, including those that might have been installed via an extension. |
#!markdown |
Indicates that the code that follows is Markdown, which can then be directly rendered as HTML in the browser. |
#!log |
Enables logging for the session. Once it has been run, detailed log information from .NET Interactive will be published along with other code outputs. |
#!about |
Displays information about the current version of .NET Interactive:![]() |
#!time |
Measures the execution time of the code submission. |
#!value |
Stores a value (from entered text, a file, or a URL), which can be accessed using #!share. |
The following magic commands are available within a C# language context.
The following magic commands are available within an F# language context.
Magic commands can be added dynamically to .NET Interactive's kernels, either at the global level or to individual language-specific subkernels. You can learn more about how to do this here.






