First steps with .NET Interactive

Microsoft has recently announced support for C# and F# in Jupyter Notebooks. On February 6, they announced a new release, Preview 2, with some naming and organizational changes.

Having recently listened to an episode of the Merge Conflict podcast where Frank Krueger spoke quite affectionately about Notebooks, I decided to give this a try.

To be sure, I have never experimented with Jupyter and my knowledge of Python is superficial at best. That is why I've only got to it now when I can use C# with Jupyter.

Installation experience

I decided to follow the first steps for the "dotnet/interactive" experience.

The installation of Anaconda took quite some time on my Ryzen 3950X desktop. It spent most of the time initializing its package cache or something.

The installation of dotnet global tool Microsoft.dotnet-interactive and a .NET kernel for Anaconda went by in a split second.

So far so good.

Running Jupyter locally with .NET

I continued with a tutorial from Microsoft's dotnet Github repo.

I launched the Anaconda Navigator, which is a Windows app, and from there I chose to run a Jupyter Notebook.

A browser windows appeared. Bummer, a web app.

I created a new file. Can I do a Hello World here? Sure I can!

Hello world, in Jupyter with C#

Following the next example, I define a new class, instantiate it and peek at its contents.

Looking at an object

Nice!

Each box I create, called a "cell", can contain either code or markdown. Therefore, I can create an interactive documentation, for instance for a consumer of my C# library, can I?

I'd expect that a markdown cell will get rendered as HTML. It does, sort-of. Out of the box, it does not support smileys, for example. This SO answer, however, provided a way: just copy-and-paste it! 😉

This is how the notebook looks like now with markdown content included:

Notebook with code and markdown

This is indeed very intriguing. Next, I am going to explore what other code I can run there. For instance, can I reference Nuget packages? Load DLLs?

Also, I'd be keen to see how I can host this notebook for the consumers of my library. I heard that I can do so directly on Github, so I am going to see about that.

To be continued!

P.S.

If you feel like we'd get along, you can follow me on Twitter, where I document my journey.

Published on

What do you think? Sound off in the comments!