Building a clone of Try.NET (.NET Interactive) in Blazor WASM (Web Assembly)
Created by Alex Hedley
Slides: https://github.com/alex-hedley/talk-blazorinteractive
Runnable .NET code on your site
[Documentation] [Code]
Install the .NET global tool nuget package. [code]
Command line tool for interactive programming with C#, F#, and PowerShell, including support for Jupyter Notebooks.
Client / Server
Install: dotnet tool install --global Microsoft.dotnet-interactive --version 1.0.431302
Run: dotnet interactive stdio --http-port 9000
npm run start
open http://127.0.0.1:8080
Some extra HTML/JS code to connect to .NET Interactive.
There are a number of events you can listen for and take action on:
Use the power of .NET and C# to build full stack web apps without writing a line of JavaScript.
Blazor WebAssembly is a single-page app (SPA) framework for building interactive client-side web apps with . NET.
Running . NET code inside web browsers is made possible by WebAssembly (abbreviated wasm).
A website to write, compile and run code, in the browser.
The anatomy of Blazor Interactive!
CSharpCompilation.CreateScriptCompilation
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true }}}%%
flowchart LR
A[SyntaxTree] --> E;
B[CompilationOptions]--> E;
C[MetadataReferences] --> E;
D[Name] --> E;
E[Compiler] --> F;
F{Emit} --> G;
G[Assembly] --> H;
H{Create} --> I;
I{Invoke} --> *;
Firstly you need to build a SyntaxTree using the code provided.
Do you want to output a DLL or a Console App?
Also you need to pass a list of usings, prob best to add System as a minimum.
Usually able to get these from the AppDomain.
More on this later...
This was added to the Blazor application .csproj so dlls weren't bundled together and we could make use of them in the list.
<PropertyGroup>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
This contains a list of the DLLs related to the project.
blazor.boot.json)
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true }}}%%
graph LR;
subgraph Page
A[Reference Filter];
B[Reference Resolver] --> C
C[Compile] --> D
D[Assembly Loader]
subgraph Load
E[Emit] --> F
F[Load]
end
subgraph Invoke
G[Create Instance] --> H
H[Invoke Member]
end
I[Console Display]
end
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true }}}%%
graph LR
A[Code] --> C
B[Assemblies] --> |web call| C
C[Compile] --> D
D[Output]
Code from the Monaco Editor, Assemblies from a web call, compiled then output to screen.
Time to show off Blazor Interactive :)
A Roslyn tool that for a given C# program shows the syntax factory API calls to construct its syntax tree.
This has been a team effort!
Thanks to Daniel Doyle ( @TheDanielDoyle) and Rob Anderson (
@jamsidedown) for their continued support and mobbing on this application.
It's been great to work alongside people to create something, instead of being a lone wolf.