Skip to content
Branch: master
Find file History
peterhuene Update Wasmtime package reference for fix.
This commit updates the .NET demo to use a fixed version of the API so that it
runs properly on Windows.
Latest commit 4540d08 Dec 5, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Add a .NET demo. Dec 2, 2019
Allocator.cs Add a .NET demo. Dec 2, 2019
Program.cs Add a .NET demo. Dec 2, 2019 Address code review feedback. Dec 3, 2019
WasmtimeDemo.csproj Update Wasmtime package reference for fix. Dec 5, 2019

Executing WebAssembly modules with .NET

This directory shows how a WebAssembly module can be executed by a .NET Core program.

While the Wasmtime for .NET API does not yet support the interface types proposal, this demonstrates how the markdown WebAssembly module can still be used from .NET.

When the Wasmtime for .NET API supports configuring Wasmtime's WASI implementation and WebAssembly interface types, this demo will be greatly simplified so that the glue code in Allocator.cs and Host.cs will no longer be necessary.

Installing a .NET Core SDK

Install a .NET Core SDK (version 3.0 or later) to build this project.

Building the WebAssembly module

If you don't have a Rust toolset install yet, use rustup to install one.

Next, install cargo-wasi for easy bootstrapping of targeting WebAssembly from Rust:

cargo install cargo-wasi

Build the markdown module:

cd ../markdown
cargo wasi build --release

Copy markdown.wasm to this directory:

cd ../dotnet
cp ../markdown/target/wasm32-wasi/release/markdown.wasm .

Running the .NET Core example

This demo will render a hardcoded Markdown string as HTML.

To run the application:

dotnet run

If everything went according to plan, this should be the result:

<h1>Hello, <code>.NET</code>! Welcome to <strong>WebAssembly</strong> with <a href="">Wasmtime</a>!</h1>
You can’t perform that action at this time.