ClockExtension
Sample¶The ClockExtension
sample walks you through how to create a simple .NET Interactive extension and package it using NuGet.
If you opened this notebook so that its working directory is in the ClockExtension
project directory, then the following cell will work. Otherwise, you should first switch your working directory to the directory containing this notebook.
#!pwsh
# 1. Build the project
dotnet build
# Pack up the NuGet package. Note, you should increment the version because the previous one, once installed, will be in your NuGet cache
dotnet pack /p:PackageVersion=1.3.5
# 3. Check that the package is there
Get-ChildItem -Recurse ClockExtension*.nupkg
Now we're ready to install the extension. We can use #i
to add the build output folder where the package is to our NuGet sources, and then #r
to install the package. Because we didn't specify a package version to install, it will choose the highest version available, which is why you should increment the version in the cell above if you experiment with making changes to the extension. (You can find out more about the #i
and #r
directives here.)
You'll need to change the file path in the #i
directive in this next cell to directory on your machine where ClockExtension.1.3.5.nupkg
was created.
#i nuget:C:\dev\interactive\samples\extensions\ClockExtension\bin\Debug\
#r "nuget:ClockExtension,1.3.5"
As you can see from the output above, the extension is able to explain a bit about what it does. So now we can try it out.
It adds a custom formatter for System.DateTime
:
DateTime.Now
The extension output also advised us to run #!clock -h
. Extensions can add magic commands and all magic commands can provide help.
#!clock -h
The #!clock
magic command help explains how to use options to set the position of the hands on the clock:
#!clock --hour 1 -m 2 -s 3