dotnet add package Wasmtime --version 13.0.0
NuGet\Install-Package Wasmtime -Version 13.0.0
<PackageReference Include="Wasmtime" Version="13.0.0" />
paket add Wasmtime --version 13.0.0
#r "nuget: Wasmtime, 13.0.0"
// Install Wasmtime as a Cake Addin #addin nuget:?package=Wasmtime&version=13.0.0 // Install Wasmtime as a Cake Tool #tool nuget:?package=Wasmtime&version=13.0.0
You can add a package reference with the .NET SDK:
$ dotnet add package wasmtime
For this introduction, we'll be using a simple WebAssembly module that imports a
hello function and exports a
(module (func $hello (import "" "hello")) (func (export "run") (call $hello)) )
To use this module from .NET, create a new console project:
$ mkdir wasmintro $ cd wasmintro $ dotnet new console
Next, add a reference to the Wasmtime package:
$ dotnet add package wasmtime
Replace the contents of
Program.cs with the following code:
using System; using Wasmtime; using var engine = new Engine(); using var module = Module.FromText( engine, "hello", "(module (func $hello (import \"\" \"hello\")) (func (export \"run\") (call $hello)))" ); using var linker = new Linker(engine); using var store = new Store(engine); linker.Define( "", "hello", Function.FromCallback(store, () => Console.WriteLine("Hello from C#!")) ); var instance = linker.Instantiate(store, module); var run = instance.GetAction("run")!; run();
Engine is created and then a WebAssembly module is loaded from a string in WebAssembly text format.
Linker defines a function called
hello that simply prints a hello message.
The module is instantiated and the instance's
run export is invoked.
To run the application, simply use
$ dotnet run
This should print
Hello from C#!.
|Product||Versions Compatible and additional computed target framework versions.|
|.NET||net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed.|
|.NET Core||netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed.|
|.NET Standard||netstandard2.0 is compatible. netstandard2.1 is compatible.|
|.NET Framework||net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed.|
|MonoAndroid||monoandroid was computed.|
|MonoMac||monomac was computed.|
|MonoTouch||monotouch was computed.|
|Tizen||tizen40 was computed. tizen60 was computed.|
|Xamarin.iOS||xamarinios was computed.|
|Xamarin.Mac||xamarinmac was computed.|
|Xamarin.TVOS||xamarintvos was computed.|
|Xamarin.WatchOS||xamarinwatchos was computed.|
NuGet packages (8)
Showing the top 5 NuGet packages that depend on Wasmtime:
Call Open Policy Agent (OPA) policies in WASM (Web Assembly) from .NET
.NET Server Local Bucketing SDK for DevCycle
Provides a configuration driven method to add WAGI modules as route endpoints to ASP.Net Core applications using WAGI.WARNING: WAGI is experimental. It is not considered production-grade by its developers, neither is it "supported" software..
Open Policy Agent (OPA) WebAssembly dotnet core SDK
A .NET API for evaluating OPA policies compiled as WebAssembly modules.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Wasmtime:
A library for running isolated .NET runtimes inside .NET
Historical and dated demos for Wasmtime usage and WASI content
Update Wasmtime to 13.0.0.