A Brief Look into .Net Interactive in Visual Studio Code

In this week’s Writer’s Room blog, Andela Community member Haymanot Tamrat explores using .NET interactive in Visual Studio Code.

In early 2020, to get started and explore dotNET REPLs, a NET developer had to install Anaconda, Jupyter, and Python. Now, all a developer has to do is install a single Visual Studio Code extension (keeping in mind that they already have VSCode and NET SDK in their toolbox).

.NET interactive Notebooks VSCode extension

Back in 2017, Try .NET was developed to keep up with the simple features of popular languages like JavaScript and GO. Net interactive gradually evolved, and now supports PowerShell, JavaScript, HTML, and SQL. It can also be used for gamification learning with polyglots – computer programs or script written in a valid form of multiple programming languages, which performs the same operations or output independent of the programming language used to compile or interpret it. We’ll explore the fundamental use cases in this article!

First, let’s create a .NET Interactive notebook in VSCode. We can create ipynb or dibformat notebooks. ipynb is the default and most widely known format on Jupyter notebookdib format is designed to be used in VSCode and only used in .NET interactive notebook. 

Ctrl + Shift + P opens the command pallet; from the pallet, we can simply create .NET Interactive: Create a new blank notebook.

Crete a notebook

Cells in the notebook can be of any type (C#, MarkDown, JS, HTML…). Each language supported by .NET Interactive has IntelliSense support. Multiple languages can be combined in a single notebook. A cell with a different language can also use the variables and properties of another cell with a different language.

.NET Interactive language mode

.NET Interactive has magic commands that can boost productivity. Unlike Jupiter notebooks, magic commands in .NET Interactive Notebooks have a prefix #!. For instance, #!DateTime. Some magic commands take an argument like #!csharp -h.

.NET Interactive Magic Commands

Let’s recap polyglot – mixing or combining multiple languages in a single notebook with the ability to access the variable of another language between cells is possible in .NET Interactive. This polyglot behavior enables developers to extend the notebook to a different level.

<h1 id="result"></h1>   //Cell 1#!csharp
StringBuilder sb = new StringBuilder();  //Cell 2
string theWord = sb.Append("Net interactive").ToString();#!javascript
#!share --from csharp sb
document.getElementById('result').innerHTML = sb;
Polyglot in Action

Visualizing charts, and diagrams are smart ways to interact with educational notebooks. By extending .NET Interactive using the NuGet package extension lab, we can create a diagram and chart with a popular language called Mermaid.

#r "nuget:Microsoft.DotNet.Interactive.Extensionlab 1.0.0-beta.22405.1"

This installs Microsoft.DotNet.Interactive.Extensionlab to our notebook project.D3.js library, and can also be used for custom visualization in our notebook projects. With the magic of polyglots, we can bind CSharp language with the HTML and JS cells to mutate the visualization and render SVG in real-time.

Mermaid Sample Example

Even though .NET is not as extensive regarding machine learning compared to python, .NET Interactive narrow downs this gap by offering a rich, interactive approach to practicing ML in .NET. We can use NuGet packages to leverage ML.Net to create supervised and unsupervised training models. Regarding ML, .Net interactive is like a Jupyter notebook with ML.Net to practice and train models.

#r "nuget:Microsoft.ML, 1.7.0"#r "nuget:Microsoft.ML.AutoML, 0.19.0"#r "nuget:XPlot.Plotly.Interactive, 4.0.6"
ML.NET In Action

Imagine not creating a full scaffold web API project to only include a REST request on a notebook for educational purposes, or even wanting to explore an API from a different REST client? This is possible! With .NET Interactive, we can use a single cell in the notebook to practice the ASP.NET application without creating a full project.

#r "nuget:Microsoft.DotNet.Interactive.aspnetcore *_*"


In this article, we’ve explored .NET Interactive in VScode. Its simplicity in hooking the notebook in a developer workstation is fascinating (we only have to install a single extension). NET Interactive offers full educational support within its Net education pack, and having kernel support for multiple languages makes it the favorite notebook for .NET developers. I hope this article gets you excited to explore.NET Interactive!

Want to be part of the Andela Community? Then join the Andela Talent Network!

With more than 175,000 technologists in our community, in over 90 countries, we’re committed to creating diverse remote engineering teams with the world’s top talent. And our network members enjoy being part of a talented community, through activities, benefits, collaboration, and virtual and in-person meetups.

All you need to do to join the Andela Talent Network is to follow our simple sign-up process. 

Submit your details via our online application then…

Complete an English fluency test – 15 minutes.

Complete a technical assessment on your chosen skill (Python, Golang, etc.) – 1 hour.

Meet with one of our Senior Developers for a technical interview – 1 hour.

Visit the Andela Talent Network sign-up page to find out more.

If you found this blog useful, check out our other blog posts for more essential insights!

Related Posts