Examples of using .NET compiled to WebAssembly in a browser application and calling a Rust-based WebAssembly code from .NET.
Prerequisites:
-
Ensure the WebAssembly build tools are installed.
dotnet workload install wasm-tools -
Ensure the .NET serve tool is installed.
dotnet tool install --global dotnet-serve
This is a .NET assembly that will be compiled into WebAssembly and then loaded into a browser page. It exposes an API, a simple math calculation and a function that encodes text into a QR Code.
(This code was inspired by this project: https://github.com/maraf/dotnet-wasm-react)
To Build:
-
Navigate to the
TestLibpath. -
Build the component.
dotnet build -c Release
This is a simple React-based web application that will load and use the generated .NET WebAssembly code.
To Run:
-
Navigate to the
webapppath. -
Install the dependencies.
npm install -
Serve the build output from
TestLibat http://localhost:4201/ (files from the build directory will be served under the/dn/path).npm run dn -
Run the web application at http://localhost:4200/
npm run dev
This is a simple Rust component that is compiled into WebAssembly.
To Build:
-
Navigate to the
rust_componentpath. -
Build the component
cargo build -
Compile the component into WebAssembly (using Interoptopus)
cargo test
This is a .NET console application that loads and calls the rust_component API.
To Run:
-
Navigate to the
Example.ConsoleAppdirectory. -
Build and run the app.
dotnet run