In this post I'll give a short introduction about the Polyglot Notebooks extension in VS Code and focus one specific element; how to update the NuGet dependencies inside your code cells when using this extension.
Let’s dive in…
Polyglot Notebooks in VS Code
As opposed to traditional notebooks that are typically used with Python, the Polyglot Notebooks VS Code extension allows you to use multiple programming languages natively all in the same notebook . It supports languages like C#, F# but also SQL, JavaScript, Powershell and more.
The Polyglot Notebooks extension is powered by .NET Interactive, an engine and API for running and editing code interactively.
A notebook is a combination of code and documentation in the same file. After installing the extension, you can open a notebook(recognizable by the ipynb extension) and execute the coding blocks by clicking on ‘play’:
Using NuGet packages inside your code blocks
Inside a code block you are not limited to C# code inside the BCL but you can reference NuGet packages using the following syntax:
#r “nuget: <package name>”
Updating NuGet packages
In the screenshot above, you can see that I’m using an older version of the Semantic Kernel package. I updated the package(s) by changing the nuget version in the code cell:
However when I tried to run the code again, it failed with the following error message:
Error: <Package Name> version <version number> cannot be added because version <previous version number> was already added
To get rid of this error, a restart of the current notebook’s kernel is required:
- Hit control-shift-p to open the Command dropdown
- Search for the Restart kernel command and hit <enter> to execute it