First look at .NET Interactive and Jupyter

Wouldn’t be nice to have a place to test some quick things with C# in Jupyter Notebook?
You can do it now!

In the beginning of February 2020, Microsoft announced the second preview of .NET Notebooks experience.

What is .NET Interactive. It is a group of CLI tools and APIs that allow the users to create interactive experience across the web, markdown and notebooks.

.NET Interactive components.

  • dotnet interactive – global tool for .NET Notebooks (Jupyter and nteract)
  • dotnet try – global tool for Workshops and office docs.
  • trydotnet.js – API (not publicly available at the moment).

How to install .NET Interactive?
As a prerequisite you need to have already installed:

Open the Anaconda Prompt (on Windows) or Terminal (on MacOS) and run this command to verify that Jupyter is installed and added to path.

>jupyter kernelspec list
Available kernels:
  python3            C:\Users\paregov\Anaconda3\share\jupyter\kernels\python3

In a regular console (Command Prompt or PowerShell) install the dotnet interactive global tool.

>tool install -g Microsoft.dotnet-interactive
You can invoke the tool using the following command: dotnet-interactive
Tool 'microsoft.dotnet-interactive' (version '1.0.110520') was successfully installed.

Install the .NET kernel in Jupyter running the following within Anaconda Prompt:

>dotnet interactive jupyter install

Welcome to .NET Interactive!
---------------------
Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience.The data is anonymous and doesn't include command-line arguments. The data is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_TRY_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

[InstallKernelSpec] Installed kernelspec .net-csharp in C:\Users\paregov\AppData\Roaming\jupyter\kernels\.net-csharp
.NET kernel installation succeeded

[InstallKernelSpec] Installed kernelspec .net-fsharp in C:\Users\paregov\AppData\Roaming\jupyter\kernels\.net-fsharp
.NET kernel installation succeeded

[InstallKernelSpec] Installed kernelspec .net-powershell in C:\Users\paregov\AppData\Roaming\jupyter\kernels\.net-powershell
.NET kernel installation succeeded

Let’s verify the installation by running in Anaconda Prompt:

>jupyter kernelspec list
Available kernels:
  .net-csharp        C:\Users\paregov\AppData\Roaming\jupyter\kernels\.net-csharp
  .net-fsharp        C:\Users\paregov\AppData\Roaming\jupyter\kernels\.net-fsharp
  .net-powershell    C:\Users\paregov\AppData\Roaming\jupyter\kernels\.net-powershell
  python3            C:\Users\paregov\Anaconda3\share\jupyter\kernels\python3

Now in the Launcher in Jupyter you should see the option to run a notebook for C#, F# and PowerShell along with Python.

Or when you add new Notebook you will see the list of available kernels.

Let’s try it now. For starter we can try just few simple things as for loops: